HerkuleX-HelloWorld

Dependencies:   herkulex mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "herkulex.h"
00003 
00004 // set serial port and baudrate, (mbed <-> HerculexX)
00005 Herkulex sv(p9, p10, 115200);
00006 
00007 int main() 
00008 {   
00009     sv.clear(0xFD);
00010     
00011     sv.setTorque(0xFD, TORQUE_ON);
00012     
00013     sv.getStatus(0xFD);
00014     
00015     sv.getPos(0xFD);
00016    
00017     while(1) 
00018     {   
00019         // POS Mode, +159.8 Degree, 100*11.2ms = 1120ms, Green LED On
00020         sv.positionControl(0xFD, 1002, 100, GLED_ON);
00021         wait(5);
00022         
00023         // POS Mode, -159.8 Degree, 100*11.2ms = 1120ms, Blue LED On
00024         sv.positionControl(0xFD, 21, 100, BLED_ON);
00025         wait(5);
00026 
00027         // TURN Mode, CCW Turn, Green LED On
00028         sv.velocityControl(0xFD, 1023, GLED_ON);
00029         wait(5);
00030         
00031         // TURN Mode, CW Turn, Blue LED On        
00032         sv.velocityControl(0xFD, -1023, BLED_ON);
00033         wait(5);
00034         
00035         // POS Mode, 0 Degree, 100*11.2ms = 1120ms, Red LED On
00036         sv.positionControl(0xFD, 512, 100, RLED_ON);
00037         wait(5);
00038         
00039         // Clear error status
00040         sv.clear(0xFD);
00041     }
00042 }