Very simple program to demonstrate MX-28 servo; turns from -90 to +90 degrees and back.
Fork of PR_RobotArmSetup by
main.cpp@1:311dbbc3aaa3, 2017-02-16 (annotated)
- Committer:
- jah128
- Date:
- Thu Feb 16 21:21:09 2017 +0000
- Revision:
- 1:311dbbc3aaa3
- Parent:
- 0:03f84c95f73b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 1:311dbbc3aaa3 | 1 | // Dynamixel MX-28 Demo Code |
jah128 | 0:03f84c95f73b | 2 | |
jah128 | 0:03f84c95f73b | 3 | #include "servo.h" |
jah128 | 0:03f84c95f73b | 4 | #include "mbed.h" |
jah128 | 0:03f84c95f73b | 5 | #include "SerialHalfDuplex.h" |
jah128 | 0:03f84c95f73b | 6 | |
jah128 | 0:03f84c95f73b | 7 | Serial pc(USBTX,USBRX); |
jah128 | 0:03f84c95f73b | 8 | Servo servo(p9,p10); |
jah128 | 0:03f84c95f73b | 9 | |
jah128 | 0:03f84c95f73b | 10 | int main() |
jah128 | 0:03f84c95f73b | 11 | { |
jah128 | 0:03f84c95f73b | 12 | pc.baud(115200); |
jah128 | 1:311dbbc3aaa3 | 13 | pc.printf("Dynamixel MX-28 Servo Demo\n"); |
jah128 | 1:311dbbc3aaa3 | 14 | int model = servo.GetModelNumber(1); |
jah128 | 1:311dbbc3aaa3 | 15 | if(model != MX28_MODEL) { |
jah128 | 1:311dbbc3aaa3 | 16 | pc.printf("Error: No MX-28 servo with ID 1 found...\n"); |
jah128 | 1:311dbbc3aaa3 | 17 | while(1); |
jah128 | 1:311dbbc3aaa3 | 18 | } |
jah128 | 1:311dbbc3aaa3 | 19 | while(1){ |
jah128 | 1:311dbbc3aaa3 | 20 | pc.printf("Set servo position to 1024"); |
jah128 | 1:311dbbc3aaa3 | 21 | servo.SetGoal(1,1024,1); |
jah128 | 1:311dbbc3aaa3 | 22 | wait(1); |
jah128 | 1:311dbbc3aaa3 | 23 | pc.printf("Set servo position to 2048"); |
jah128 | 1:311dbbc3aaa3 | 24 | servo.SetGoal(1,2048,1); |
jah128 | 1:311dbbc3aaa3 | 25 | wait(1); |
jah128 | 1:311dbbc3aaa3 | 26 | pc.printf("Set servo position to 3072"); |
jah128 | 1:311dbbc3aaa3 | 27 | servo.SetGoal(1,3072,1); |
jah128 | 1:311dbbc3aaa3 | 28 | wait(1); |
jah128 | 1:311dbbc3aaa3 | 29 | pc.printf("Set servo position to 2048"); |
jah128 | 1:311dbbc3aaa3 | 30 | servo.SetGoal(1,2048,1); |
jah128 | 1:311dbbc3aaa3 | 31 | wait(1); |
jah128 | 1:311dbbc3aaa3 | 32 | } |
jah128 | 1:311dbbc3aaa3 | 33 | } |