Last active
December 6, 2015 22:50
-
-
Save treeherder/dac4f7b2bc98f042adb0 to your computer and use it in GitHub Desktop.
some scripts for turret firmware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef POSES | |
#define POSES | |
#include <avr/pgmspace.h> | |
PROGMEM prog_uint16_t Center[] = {8, 512, 512, 512, 512, 512, 512, 512, 512}; | |
PROGMEM prog_uint16_t Home[] = {8, 512, 380, 644, 340, 684, 561, 512, 512}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ax12.h> | |
#include <BioloidController.h> | |
#include "poses.h" | |
BioloidController bioloid = BioloidController(1000000); | |
void setup(){ | |
pinMode(0,OUTPUT); | |
Serial.begin(115200); | |
delay (500); | |
Serial.println("###########################"); | |
Serial.println("Serial Communication Established."); | |
CheckVoltage(); | |
menu(); | |
} | |
void loop(){ | |
int inByte = Serial.read(); | |
switch (inByte) { | |
case '1': | |
increase_pos(1); | |
break; | |
case '2': | |
// base_right(); | |
break; | |
case 'h': | |
MoveHome(); | |
break; | |
case 'r': | |
RelaxServos(); | |
break; | |
case 'c': | |
MoveCenter(); | |
break; | |
case 'v': | |
CheckVoltage(); | |
break; | |
case 'l': | |
LEDTest(); | |
break; | |
default: | |
menu() | |
break | |
} | |
} | |
void CheckVoltage(){ | |
// wait, then check the voltage (LiPO safety) | |
float voltage = (ax12GetRegister (1, AX_PRESENT_VOLTAGE, 1)) / 10.0; | |
Serial.println("###########################"); | |
Serial.print ("System Voltage: "); | |
Serial.print (voltage); | |
Serial.println (" volts."); | |
if (voltage < 10.0){ | |
Serial.println("Voltage levels below 10v, please charge battery."); | |
while(1); | |
} | |
if (voltage > 10.0){ | |
Serial.println("Voltage levels nominal."); | |
} | |
} | |
void MoveCenter(){ | |
delay(100); // recommended pause | |
bioloid.loadPose(Center); // load the pose from FLASH, into the nextPose buffer | |
bioloid.readPose(); // read in current servo positions to the curPose buffer | |
Serial.println("###########################"); | |
Serial.println("Moving servos to centered position"); | |
Serial.println("###########################"); | |
delay(1000); | |
bioloid.interpolateSetup(1000); // setup for interpolation from current->next over 1/2 a second | |
while(bioloid.interpolating > 0){ // do this while we have not reached our new pose | |
bioloid.interpolateStep(); // move servos, if necessary. | |
delay(3); | |
} | |
} | |
void MoveHome(){ | |
delay(100); // recommended pause | |
bioloid.loadPose(Home); // load the pose from FLASH, into the nextPose buffer | |
bioloid.readPose(); // read in current servo positions to the curPose buffer | |
Serial.println("###########################"); | |
Serial.println("Moving servos to Home position"); | |
Serial.println("###########################"); | |
delay(1000); | |
bioloid.interpolateSetup(1000); // setup for interpolation from current->next over 1/2 a second | |
while(bioloid.interpolating > 0){ // do this while we have not reached our new pose | |
bioloid.interpolateStep(); // move servos, if necessary. | |
delay(3); | |
} | |
} | |
int get_pos(int servo_id){ | |
int pos; | |
pos = ax12GetRegister(servo_id, 36, 2); | |
Serial.print("Servo Position: "); | |
Serial.println(pos); | |
if (pos < 0){ | |
return -1; | |
}else if (pos >=0){ | |
return pos; | |
} | |
} | |
int increase_pos(int id){ | |
int pos = get_pos(id); | |
SetPosition(1, pos + 1 ); | |
delay(10); | |
return pos; | |
} | |
/* while(pos <= 512){ | |
SetPosition(1, pos); | |
pos = pos++; | |
delay(10); | |
} | |
delay(500); | |
// Shoulder Servos Test | |
Serial.println("Moving Servo IDs: 2 & 3 (Shoulder)"); | |
while(pos >= 312){ | |
SetPosition(2, pos); | |
SetPosition(3, pos2); | |
pos = pos--; | |
pos2 = pos2++; | |
delay(10); | |
} | |
while(pos <= 512){ | |
SetPosition(2, pos); | |
SetPosition(3, pos2); | |
pos = pos++; | |
pos2 = pos2--; | |
delay(10); | |
} | |
delay(500); | |
// Elbow Servo Test | |
Serial.println("Moving Servo IDs: 4 & 5 (Elbow)"); | |
while(pos <= 712){ | |
SetPosition(4, pos); | |
SetPosition(5, pos2); | |
pos = pos++; | |
pos2 = pos2--; | |
delay(10); | |
} | |
while(pos >= 512){ | |
SetPosition(4, pos); | |
SetPosition(5, pos2); | |
pos = pos--; | |
pos2 = pos2++; | |
delay(10); | |
} | |
delay(500); | |
//Wrist Servo Test | |
Serial.println("Moving Servo ID: 6"); | |
while(pos <= 712){ | |
SetPosition(6, pos); | |
pos = pos++; | |
delay(10); | |
} | |
while(pos >= 512){ | |
SetPosition(6, pos); | |
pos = pos--; | |
delay(10); | |
} | |
delay(500); | |
//Wrist Rotate Servo Test | |
Serial.println("Moving Servo ID: 7"); | |
while(pos >= 312){ | |
SetPosition(7, pos); | |
pos = pos--; | |
delay(10); | |
} | |
while(pos <= 512){ | |
SetPosition(7, pos); | |
pos = pos++; | |
delay(10); | |
} | |
delay(500); | |
//Gripper Servo Test | |
Serial.println("Moving Servo ID: 8"); | |
while(pos >= 312){ | |
SetPosition(8, pos); | |
pos = pos--; | |
delay(10); | |
} | |
while(pos <= 512){ | |
SetPosition(8, pos); | |
pos = pos++; | |
delay(10); | |
} | |
delay(500); | |
if (RunCheck == 1){ | |
menu(); | |
} | |
} | |
*/ | |
void menu(){ | |
Serial.println("###########################"); | |
Serial.println("Please enter option 1-5 to run individual tests again."); | |
Serial.println("1) Servo Scanning Test"); | |
Serial.println("2) Move Servos to Center"); | |
Serial.println("3) Move Servos to Home"); | |
Serial.println("4) Relax Servos"); | |
Serial.println("5) Perform Movement Sign Test"); | |
Serial.println("6) Check System Voltage"); | |
Serial.println("7) Perform LED Test"); | |
Serial.println("###########################"); | |
} | |
void RelaxServos(){ | |
id = 1; | |
Serial.println("###########################"); | |
Serial.println("Relaxing Servos."); | |
Serial.println("###########################"); | |
while(id <= SERVOCOUNT){ | |
Relax(id); | |
id = (id++)%SERVOCOUNT; | |
delay(50); | |
} | |
if (RunCheck == 1){ | |
menu(); | |
} | |
} | |
void LEDTest(){ | |
id = 1; | |
Serial.println("###########################"); | |
Serial.println("Running LED Test"); | |
Serial.println("###########################"); | |
while(id <= SERVOCOUNT){ | |
ax12SetRegister(id, 25, 1); | |
Serial.print("LED ON - Servo ID: "); | |
Serial.println(id); | |
delay(3000); | |
ax12SetRegister(id, 25, 0); | |
Serial.print("LED OFF - Servo ID: "); | |
Serial.println(id); | |
delay(3000); | |
id = id++; | |
} | |
if (RunCheck == 1){ | |
menu(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment