2 years, 5 months ago.

Very basic control problem of Dynamixel MX28T servo

Beginner needs help here! I am trying to control a mx28T servo using my mbed NXP LPC1768. But it is not working, no response :(

I used the library from Georgios Petrou (https://os.mbed.com/users/GIPetrou/code/MX28/) and the code I am using is:

<<code>> before and <</code>>#include "mbed.h" <<code>> before and <</code>>#include "MX28.h" <<code>> before and <</code>>#include "mbed.h" <<code>> before and <</code>>#include "MX28.h" <<code>> before and <</code>>#include "MX28.h" <<code>> before and <</code>>#define MX28_DEBUG

<<code>> before and <</code>>MX28 mx28 (p9, p10, 57142); <<code>> before and <</code>>DigitalIn up(p15); <<code>> before and <</code>>DigitalIn down(p12); <<code>> before and <</code>>bool moving = false; <<code>> before and <</code>>MX28 mx28 (p9, p10, 57142); <<code>> before and <</code>>DigitalIn up(p15); <<code>> before and <</code>>DigitalIn down(p12); <<code>> before and <</code>>bool moving = false; <<code>> before and <</code>>DigitalIn up(p15); <<code>> before and <</code>>DigitalIn down(p12); <<code>> before and <</code>>bool moving = false; <<code>> before and <</code>>DigitalIn down(p12); <<code>> before and <</code>>bool moving = false; <<code>> before and <</code>>bool moving = false; <<code>> before and <</code>>int main() {

<<code>> before and <</code>> uint8_t servo1 = 0x01;

<<code>> before and <</code>> while (1) { <<code>> before and <</code>> if (up == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> while (1) { <<code>> before and <</code>> if (up == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> if (up == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> else if (down == 1) <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> mx28.SetMovingSpeed(servo1, 100, true); <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> moving = true; <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> else <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> { <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> mx28.SetMovingSpeed(servo2, 100, false); <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> mx28.SetGoalPosition(servo1, mx28.GetPresentPosition(servo1)); <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>> } <<code>> before and <</code>>}

I set the servo Id and baudrate.( My case is 0x07and 57142)

the connection is also very simple. TX and RX (p9 and p10) connect together to the TTL Data line of the servo. common ground is connected between the mbed board and the servo.

what else can the problem be??? have tried for several days but all failed ........

Hi there, it looks like your code snippet didn't paste correctly. Can you try re-pasting and wrapping your code with the <<code>> tags?

- Jenny, team Mbed

posted by Jenny Plunkett 09 Apr 2018

Oh sorry even not notice this problem, thanks, let me try again

posted by le zhu 09 Apr 2018

1 Answer

2 years, 5 months ago.

Still have no idea how to post code correctly here, first time to use this forum and cannot delete the wrong try and where is the tutorial for using this? Instead, I post the picture of code I am using./media/uploads/LeZHU/----_2018-04-10_01.01.51.png