Wednesday, 26 August 2015

Week 5

The rest of the leg test parts finished printing, and they fit almost perfectly. Here's a quick video of the hip and knee joints moving.




The code behind this motion is as follows:

#include <Servo.h>

// Instantiate servos
Servo sFLcoxaLat;   // Rotation around the vertical axis
Servo sFLcoxaLon;   // Rotation around the horizontal axis pointing forward

int pFLcoxaLat = 0;
int pFLcoxaLon = 0;

// Instantiate global figures
int servoSpeed = 2;

void setup() {
  sFLcoxaLat.attach(2);
  sFLcoxaLon.attach(3);
}

void loop() {
  // Raise femur
  for(pFLcoxaLat = 0; pFLcoxaLat <= 90; pFLcoxaLat += servoSpeed)
  {
    sFLcoxaLat.write(pFLcoxaLat);
    delay(15);
  }
  
  // Extend tibia
  for(pFLcoxaLon = 0; pFLcoxaLon <= 90; pFLcoxaLon += servoSpeed)
  {
    sFLcoxaLon.write(pFLcoxaLon);
    delay(15);
  }
  
  // Lower femur
  for(pFLcoxaLat = 90; pFLcoxaLat >= 0; pFLcoxaLat -= servoSpeed)
  {
    sFLcoxaLat.write(pFLcoxaLat);
    delay(15);
  }

  // Retract tibia
  for(pFLcoxaLon = 90; pFLcoxaLon >= 0; pFLcoxaLon -= servoSpeed)
  {
    sFLcoxaLon.write(pFLcoxaLon);
    delay(15);
  }
}

Really, it's quite simple for what it does. Each motion that the hexapod will make, such as walking and turning, will just be a function with similar contents to those of loop() above. 

The rest of the body will take about 6 hours of elapsed printing time to complete, so I've left a list of required parts that will hopefully be completed overnight for pickup on Friday. Optimistically, I think construction could be complete by the end of this coming weekend.

No comments:

Post a Comment