Joint Mode Arduino Code
Joint Mode Arduino Code
h>
#define BOARD_BUTTON_PIN 23
#if defined(ARDUINO_OpenCM904) // When using official ROBOTIS board with DXL circuit.
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on
the OpenCM 9.04 board)
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the
OpenCM 9.04 board)
#endif
//leg1
//leg2
//leg3
//leg4
const uint8_t L4motor1 = 41;
void setup() {
pinMode(BOARD_BUTTON_PIN, INPUT_PULLDOWN);
DEBUG_SERIAL.begin(115200);
dxl.begin(1000000);
dxl.setPortProtocolVersion(2);
//////////////////////////////leg1
//moto1
dxl.ping(L1motor1);
dxl.torqueOff(L1motor1);
dxl.setOperatingMode(L1motor1, OP_POSITION);
dxl.torqueOn(L1motor1);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//motor2
dxl.ping(L1motor2);
dxl.torqueOff(L1motor2);
dxl.setOperatingMode(L1motor2, OP_POSITION);
dxl.torqueOn(L1motor2);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//motor3
dxl.ping(L1motor3);
dxl.torqueOff(L1motor3);
dxl.setOperatingMode(L1motor3, OP_POSITION);
dxl.torqueOn(L1motor3);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//wheelmotor4
dxl.ping(L1motor4);
dxl.torqueOff(L1motor4);
dxl.setOperatingMode(L1motor4, OP_VELOCITY);
dxl.torqueOn(L1motor4);
/////////////////////////////////
//////////////////leg2
//motor1
dxl.ping(L2motor1);
dxl.torqueOff(L2motor1);
dxl.setOperatingMode(L2motor1, OP_POSITION);
dxl.torqueOn(L2motor1);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
dxl.ping(L2motor2);
dxl.torqueOff(L2motor2);
dxl.setOperatingMode(L2motor2, OP_POSITION);
dxl.torqueOn(L2motor2);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//motor3
dxl.ping(L2motor3);
dxl.torqueOff(L2motor3);
dxl.setOperatingMode(L2motor3, OP_POSITION);
dxl.torqueOn(L2motor3);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//wheelmotor4
dxl.ping(L2motor4);
dxl.torqueOff(L2motor4);
dxl.setOperatingMode(L2motor4, OP_VELOCITY);
dxl.torqueOn(L2motor4);
///////////----------------------//////////////////////
//////////////////////////////leg3
//moto1
dxl.ping(L3motor1);
dxl.torqueOff(L3motor1);
dxl.setOperatingMode(L3motor1, OP_POSITION);
dxl.torqueOn(L3motor1);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//dxl.writeControlTableItem(PROFILE_VELOCITY, DXL_ID, 30);
//motor2
dxl.ping(L3motor2);
dxl.torqueOff(L3motor2);
dxl.setOperatingMode(L3motor2, OP_POSITION);
dxl.torqueOn(L3motor2);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//motor3
dxl.ping(L3motor3);
dxl.torqueOff(L3motor3);
dxl.setOperatingMode(L3motor3, OP_POSITION);
dxl.torqueOn(L3motor3);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//wheelmotor4
dxl.ping(L3motor4);
dxl.torqueOff(L3motor4);
dxl.setOperatingMode(L3motor4, OP_VELOCITY);
dxl.torqueOn(L3motor4);
/////////////////////////////////
//////////////////leg4
//motor1
dxl.ping(L4motor1);
dxl.torqueOff(L4motor1);
dxl.setOperatingMode(L4motor1, OP_POSITION);
dxl.torqueOn(L4motor1);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//motor2
dxl.ping(L4motor2);
dxl.torqueOff(L4motor2);
dxl.setOperatingMode(L4motor2, OP_POSITION);
dxl.torqueOn(L4motor2);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//motor3
dxl.ping(L4motor3);
dxl.torqueOff(L4motor3);
dxl.setOperatingMode(L4motor3, OP_POSITION);
dxl.torqueOn(L4motor3);
// Limit the maximum velocity in Position Control Mode. Use 0 for Max speed
//wheelmotor4
dxl.ping(L4motor4);
dxl.torqueOff(L4motor4);
dxl.setOperatingMode(L4motor4, OP_VELOCITY);
dxl.torqueOn(L4motor4);
stand();
delay(2000);
//walk();
//wheel();
///////////////////////////////end of config
void stand(){
//
//
//
/*
* //delay(400);
DEBUG_SERIAL.println(dxl.getPresentPosition(L1motor1));
DEBUG_SERIAL.println(dxl.getPresentPosition(L4motor1));
*/
}
void wheel(){
dxl.setGoalVelocity(L1motor4, 250);
dxl.setGoalVelocity(L2motor4, 250);
dxl.setGoalVelocity(L3motor4, 250);
dxl.setGoalVelocity(L4motor4, 250);
void counterLeft(){
void counterRight(){
void stay(){
void walk(){
//leg1
//leg3
//leg2
//leg4
delay(600);
//leg1
//leg3
//leg2
//leg4
delay(600);
void pace(){
int initial_present_position = 0;
int final_present_position = 180;
delay(800);
dxl.setGoalPosition(L1motor1,220, UNIT_DEGREE);
initial_present_position = dxl.getPresentPosition(L1motor2);
delay(800);
void amble(){
delay(100);
delay(900);
delay(900);
void loop(){
walk();
//amble();
//wheel;