4-20 2,812 views
注:视频建议到优酷网站选择高清播放
一、XBee模块的设置方式
二、PC通过XBee无线模块与Arbotix-M控制板通信控制AX-12A舵机
三、附录(相关测试代码)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
#include <ax12.h> #include <BioloidController.h> #include "poses.h" BioloidController bioloid = BioloidController(1000000); const int SERVOCOUNT = 5; int id; int pos; boolean IDCheck; boolean RunCheck; void setup(){ pinMode(0,OUTPUT); //initialize variables id = 1; pos = 0; IDCheck = 1; RunCheck = 0; //open serial port //a Serial.begin(9600); Serial.begin(38400); delay (500); Serial.println("###########################"); Serial.println("Serial Communication Established."); //Check Lipo Battery Voltage //a CheckVoltage(); MoveCenter(); //Scan Servos, return position. //a ScanServo(); //a MoveTest(); MoveHome(); //a MenuOptions(); RunCheck = 1; } void loop(){ // read the sensor: int inByte = Serial.read(); switch (inByte) { case '1': ScanServo(); break; case '2': MoveCenter(); break; case '3': MoveHome(); break; case '4': RelaxServos(); break; case '5': MoveCenter(); MoveTest(); break; case '6': CheckVoltage(); break; case '7': LEDTest(); break; } } void ScanServo(){ id = 1; Serial.println("###########################"); Serial.println("Starting Servo Scanning Test."); Serial.println("###########################"); while (id <= SERVOCOUNT){ pos = ax12GetRegister(id, 36, 2); Serial.print("Servo ID: "); Serial.println(id); Serial.print("Servo Position: "); Serial.println(pos); if (pos <= 0){ Serial.println("###########################"); Serial.print("ERROR! Servo ID: "); Serial.print(id); Serial.println(" not found. Please check connection and verify correct ID is set."); Serial.println("###########################"); IDCheck = 0; } id = (id++)%SERVOCOUNT; delay(1000); } if (IDCheck == 0){ Serial.println("###########################"); Serial.println("ERROR! Servo ID(s) are missing from Scan. Please check connection and verify correct ID is set."); Serial.println("###########################"); } else{ Serial.println("All servo IDs present."); } if (RunCheck == 1){ MenuOptions(); } } 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."); } if (RunCheck == 1){ MenuOptions(); } Serial.println("###########################"); } 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); } if (RunCheck == 1){ MenuOptions(); } } 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); } if (RunCheck == 1){ MenuOptions(); } } void MoveTest(){ Serial.println("###########################"); Serial.println("Initializing Movement Sign Test"); Serial.println("###########################"); delay(500); id = 1; pos = 512; while(id <= SERVOCOUNT){ Serial.print("Moving Servo ID: "); Serial.println(id); while(pos >= 312){ SetPosition(id, pos); pos = pos--; delay(10); } while(pos <= 512){ SetPosition(id, pos); pos = pos++; delay(10); } //iterate to next servo ID id = id++; } if (RunCheck == 1){ MenuOptions(); } } void MenuOptions(){ 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){ MenuOptions(); } } 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){ MenuOptions(); } } |
poses.h文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#ifndef POSES #define POSES #include <avr/pgmspace.h> //PROGMEM prog_uint16_t Center[] = {5, 512, 512, 512, 512, 512}; //PROGMEM prog_uint16_t Home[] = {5, 512, 376, 1000, 430, 512}; PROGMEM prog_uint16_t Center[] = {5, 512, 512, 512, 512, 512}; PROGMEM prog_uint16_t Home[] = {5, 0, 0, 0, 0, 0}; #endif |