PDA

View Full Version : Timeout problem with Forest Moon Dynamixel library



Pi Robot
01-29-2010, 09:13 AM
Hello,

I was wondering if the famous Fergy on this forum is the same Fergy who wrote the most excellent Dynamixel library over at forestmoon.com. If so, first of all, thanks for coding the library--it is simply awesome! However, I am struggling with a timeout problem I was hoping to get some help with.

I have 10 Dynamixel AX-12+ servos connected to a CM-5 controller which in turn is connected to my PC via an RS-232 to USB adapter. I am running the serial connection at 57600 baud but the connection between CM-5 and servos is the default 1 Mb/s. My control program is written in C# and I am referencing the Dynamixel.dll library.

Everything runs beautifully if I simply send goal positions and speeds to the servos. I am running them in Synchronized mode and I execute the Synchronize() command inside a 50ms timer. The trouble happens when I add any commands to query the current positions of the servos. I do this inside the same timer loop and just before the call to Synchronize(). As soon as I add a position query, eventually I get a Timeout error back from the serial port connected to the CM-5. It can take anywhere from 30 seconds to several minutes before I get the error but it always happens eventually.

I've checked or replaced all the servo cables and I am powering the CM-5 with the 12v brick it came with.

My timer tick handler looks like this:


private void ServoTimer_Tick(object sender, EventArgs e)
{
// Synchronize all servo writes to the Dynamixel C5 controller and read back positions.
if (EnableServos.Checked)
{
sensorValues[Sensors.SensorID.HeadPan] = myActuators.HeadPan.CurrentPosition;
sensorValues[Sensors.SensorID.HeadTilt] = myActuators.HeadTilt.CurrentPosition;
sensorValues[Sensors.SensorID.LeftShoulderOutPosition] = myActuators.LeftShoulderOut.CurrentPosition;
sensorValues[Sensors.SensorID.LeftShoulderUpPosition] = myActuators.LeftShoulderUp.CenterPosition;

myControllers.DynaNet.Synchronize();
}
}
I could live with the time out if I could catch it and some how recover but there doesn't seem to be a way to handle the exception and I have to power cycle the CM-5 to get things working again. I've even set the timeout on the serial port to 10 seconds. The code I use to initialize the CM-5 is borrowed from the Forest Moon AX-12 Arm code as follows:


public void StartDynamixels()
{
string DynaSerialPort = "COM10";
string DynaBaudRate = "57600";
bool UseDialog = false;

DynaPort = SelectPort.ConfigurePort(ref DynaSerialPort, ref DynaBaudRate, ref UseDialog);
DynaPort.BaseStream.ReadTimeout = 10000;
DynaPort.BaseStream.WriteTimeout = 10000;

try
{
DynaNet = new DynamixelNetwork(DynaPort.BaseStream);

// try to enter Toss Mode (in case we're connected to a CM-5)
try { DynaNet.EnterTossMode(); }
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error entering Dynamixel Toss Mode");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error during Dynamixel startup");
}

NetControl = new DynNetController(DynaNet);

while (DynaNet.Dynamixels.Count != 10)
{
Thread.Sleep(100);
DynaNet.Scan(1, 10);
}
if (DynaNet.Dynamixels.Count != 10)
Console.WriteLine("The Dynamixel configuration is not as expected.");

// Set all the motor speeds to a sensible start value.
DynaNet.BroadcastRegister(Dynamixel.Register.Movin gSpeed, 100);
}Any ideas would be greatly appreciated!

--patrick

http://www.pirobot.org

lnxfergy
01-29-2010, 09:24 AM
Nope. I be Mike Ferguson. I've never actually powered on my CM-5s.... I've created PyPose and the ArbotiX to replace the robotis software/hardware.

-Fergs

Pi Robot
01-29-2010, 09:29 AM
OK, thanks Mike. Well, if anyone has any ideas anyway, please shout out.

Thanks!
patrick

MikeG
01-29-2010, 07:53 PM
How do I say this... You're trying to execute methods designed to be synchronous and half duplex, asynchronously and full duplex. When you execute a read command the code blocks until a status packet is received one byte at a time. So if the code is blocking and the timer is ticking well... you get threading and probably collision issues.

If you can hang tight for about 2-3 weeks (9-5 job is getting in the way), I'll have open source code that acts just like a Dynamixel network. See Alpha=> http://www.agaverobotics.com/services/dotnet/Dynamixel/default.aspx. I don't use a CM-5 but can easily wire up a connection in toss mode.

Pi Robot
01-30-2010, 09:29 AM
Hi MikeG,

Many thanks for your reply. Your explanation makes perfect sense and it gave me an idea for a workaround which seems to be working. Instead of using a timer to synchronize and poll the AX-12's, I am now using a regular thread with a small (5ms) delay between each read or write. So far, I have yet to see a timeout exception using this method even after running it for 20 minutes.

In the meantime, your open source project looks great and I'll be sure to check it out when you get it finished.

Thanks again!

--patrick

http://www.pirobot.org

MikeG
01-30-2010, 01:35 PM
Well, cool that's a simple fix.

Adam
05-03-2010, 08:48 PM
Does the Forest Moon code work to control an RX servo through the USB2Dynamixel?

MikeG
05-03-2010, 10:35 PM
Yes it does.

The Forest Moon stuff is very well written.

I'm not the brightest bulb on the strip so I wrote USB2Dynamixel code that worked for my brain. Each instruction is a class.
http://www.agaverobotics.com/services/dotnet/Dynamixel/default.aspx

Adam
05-04-2010, 09:36 AM
Thanks for the reply. I'm going to do some experimenting. Maybe I'll check out your code as well. The Forest Moon code works, but I agree with your comment. I don't think that way either.

Pi Robot
05-04-2010, 09:38 AM
I finally solved the timeout issue I was having ealier. Scott Ferguson, author of the Dynamixel library I am using (http://www.forestmoon.com/Software/AX12ArmSample/), kindly pointed out to me that there was no need to use the CM-5's RS-232 connection since I have a USB2Dynamixel device. Controlling the Dynamixels over the TTL connection instead of RS-232 instantly resolved all my timeout problems. Even better, I can now run at 1 Mb/s instead of 56k and I no longer have to insert delays between queries to the Dynamixels. So the bottom line is: don't use a Serial-USB converted and then attach it to the CM-5's serial port. Use the TTL connection instead. (Although I still use the CM-5 as a power hub and bus distribution point.)

--patrick

http://www.pirobot.org (http://www.pirobot.org/)

DresnerRobotics
05-04-2010, 11:06 AM
I finally solved the timeout issue I was having ealier. Scott Ferguson, author of the Dynamixel library I am using (http://www.forestmoon.com/Software/AX12ArmSample/), kindly pointed out to me that there was no need to use the CM-5's RS-232 connection since I have a USB2Dynamixel device. Controlling the Dynamixels over the TTL connection instead of RS-232 instantly resolved all my timeout problems. Even better, I can now run at 1 Mb/s instead of 56k and I no longer have to insert delays between queries to the Dynamixels. So the bottom line is: don't use a Serial-USB converted and then attach it to the CM-5's serial port. Use the TTL connection instead. (Although I still use the CM-5 as a power hub and bus distribution point.)

--patrick

http://www.pirobot.org (http://www.pirobot.org/)

Free yourself from the CM-5! http://www.trossenrobotics.com/store/p/5886-SMPS2Dynamixel-Adapter.aspx

:p

Pi Robot
05-04-2010, 12:21 PM
Thanks for the link Tyberius. BTW, is there a way to make the USB2Dynamixel wireless while still using the TTL connection? The rest of my robot can be made wireless--the Serializer microcontroller and the D-Link 920 video camera. One of the reasons I started with the CM5 is that there are wireless options for it. But I'm not sure if you can get rid of the cable with the USB2Dynamixel. (And I don't mean using it as USB-Serial converter--I mean using it as a TTL controller.) What do you think?

--patrick

JonHylands
05-04-2010, 02:04 PM
You can use my wifi board to get a full speed wireless link to the bus from a PC...

http://www.huvrobotics.com/shop/index.php?_a=viewProd&productId=8

- Jon

Pi Robot
05-04-2010, 03:07 PM
Thanks Jon--that looks really nice. Unfortunately, I'm saving my pennies to get a Bumblebee2 stereo camera from Point Grey Research so other bigger ticket items will have to wait for now. But it's good to know you have this out there.

--patrick

Pi Robot
05-04-2010, 03:10 PM
Free yourself from the CM-5! http://www.trossenrobotics.com/store/p/5886-SMPS2Dynamixel-Adapter.aspx

:p

In addition to the SMPS2Dynamixel adapter, I was looking for a part I already have (but would like to have another) and I think it came with either the Bioloid Beginner's kit or the frame kit. It is a tiny 6-port bus expansion board for AX-12 connections (3 pin). I'm not finding it in your store--am I just missing it somewhere?

Thanks,
patrick

iBot
05-04-2010, 04:30 PM
If you can't find the adapter, the connector sockets are available at low cost. Being 0.1 ptich, they fit into perf board and the wiring is a simple bus.
I usually cyano glue the connector bodies to the board as well, since the plugs are sometimes fairly tough to pull out of the housing and can leave the pins behind.

DresnerRobotics
05-04-2010, 05:11 PM
In addition to the SMPS2Dynamixel adapter, I was looking for a part I already have (but would like to have another) and I think it came with either the Bioloid Beginner's kit or the frame kit. It is a tiny 6-port bus expansion board for AX-12 connections (3 pin). I'm not finding it in your store--am I just missing it somewhere?

Thanks,
patrick

Robotis doesn't offer them individually... yet. I put in a request to get them though, and they said they'd work something out. So hopefully soon!

MikeG
05-04-2010, 07:07 PM
I have other code... still has a bug in the response parser... but you're welcome to it. It uses listeners to update memory resident Dynamixel control table objects.

Pi Robot
05-05-2010, 11:54 AM
Thanks to all the good suggestions here, I have removed the CM-5 from my robot. I wired one of my three-pin AX-12 cables into my power source and I'm using the little 6-port bus I have to hook it up to all the servos. Works like a charm! BTW, I am getting the impression from some of the CM-5 posts I have read that it is not highly regarded as a controller. Since I don't know much about the hardware, can someone enlighten me? (Of course, my original timeout problem might be a good example...)

Thanks!
patrick

MikeG
05-05-2010, 05:51 PM
The CM-5 is a great controller and designed to be used with the Bioloid software. That constraint might limit your project - might not.

Pi Robot
05-05-2010, 11:21 PM
Thanks Mike. OK, here is a question that I hope is not out in left field. I have a BlueSMiRF modem from SparkFun that I bought a long time ago to use with a BrainStem controller. What are the chances I could use this as a wireless connection to my AX-12+ network? I already have Bluetooth set up and running on my host PC. And if I am reading the BlueSMiRF documentation correctly, the Rx and Tx pins are TTL. Does this mean I can connect them directly into the AX-12+ network without using the USB2Dynamixel controller? Or is the USB2Dynamixel controller doing more than simply acting as a USB to TTL bridge?

If I can use the BlueSMiRF in this way, what two pins on the AX 3-pin connector would I connect the Rx and Tx pins to from the BlueSMiRF? BTW, here is the SparkFun page for the BlueSMiRF:

http://www.sparkfun.com/commerce/product_info.php?products_id=582

MikeG
05-06-2010, 08:55 AM
Here's the problem... the AX-12 network is a 1/2 duplex 1Mbps (default) serial bus. The Bluesmirf is a full duplex 9600 to 115200 bps serial bus.

A full duplex bus uses one wire for transmit and one for receive. A 1/2 duplex bus uses one wire for both Rx/Tx. Conversion can be done with a transistor circuit or a tri-state buffer.

The AX-12s come default at 1Mbps, you'll need to knock down the AX-12 baud to something the bluesmirf can handle.

I built a driver for the Parallax Propeller in assembly that will do all the translation but you would need a Propeller.
http://www.parallax.com/Store/Microcontrollers/PropellerDevelopmentBoards/tabid/514/List/0/CategoryID/73/Level/a/SortField/0/Default.aspx

Pi Robot
05-06-2010, 01:23 PM
Thanks for the explanation--I think I actually understand it now. Since I've gone through the trouble of adding a mini-ITX computer to my robot, I think I'll postpone the wireless option for now. I was just hoping there was something easy and not too expensive.

--patrick

MikeG
05-06-2010, 03:14 PM
USB wifi?

Pi Robot
05-06-2010, 03:32 PM
Something like this perhaps?

http://www.cablestogo.com/product.asp?cat_id=1542&sku=29570&relatedItem=true

Still somewhat expensive and a range of only 30 feet line of sight which seems a little restrictive...

MikeG
05-06-2010, 06:33 PM
Amazon.com: Medialink - Wireless G USB Adapter - 802.11g - 54Mbps - Windows 2000 / XP / Vista 32-Bit / Vista 64-Bit / Windows 7 Compatible: Electronics

Pi Robot
05-08-2010, 08:31 AM
I think maybe we're looking at different things. I would need something to make the USB2Dynamixel wireless which I think would require a wireless USB connection, not a wireless 802.11g network connection.

MikeG
05-08-2010, 09:01 AM
I guess I don't understand. Why can't you connect the USB2Dyanmxel to an ITX USB port then to the AX-12 bus?

Pi Robot
05-08-2010, 09:13 AM
Oh, sorry about the confusion. The idea is to remotely control the robot without having to use the mini-ITX. When I am developing the code, it is easier just to plug the robot into my desktop PC using USB cables. However, for testing navigation stuff (for example), it would be nice to get rid of the USB cables. I only have the mini-ITX for possible fully autonomous behavior. Of course, the CM-5 can be made wireless, but then I'm back to the timeout issues with the Forest Moon library. So I was hoping for a wireless solution for the USB2Dynamixel.

DresnerRobotics
05-08-2010, 10:05 AM
Jon's new wifi adapter (we have it in stock here now as well) is probably going to be your best bet. I have the feeling that a USB Wifi adapter might introduce some latency/timeout problems. That technology isn't the most mature of wifi tech.

Pi Robot
05-08-2010, 02:07 PM
Yeah, I really like the looks of Jon's wifi adapter for this purpose. One question though: the Forest Moon library does its thing over a serial port, but Jon's board uses TCP sockets. Is it possible to "fake" a serial port in front of the TCP socket so that I could still use the Forest Moon library? Hope that makes sense--I haven't programmed with sockets before though I get the general idea.

Pi Robot
05-10-2010, 10:31 AM
The CM-5 is a great controller and designed to be used with the Bioloid software. That constraint might limit your project - might not.

I went back to trying my CM-5 using the USB2Dynamixel in RS-232 mode. Then I set the robot running on its own to see how long it would go before a timeout. It took about 20 minutes, and then the CM-5 had to be power-cycled to clear the timeout block. I have never seen this timeout problem with the USB2Dynamixel running in TTL mode. So Mike, I was wondering if you are able to try your library with a CM-5 in "toss mode" to see if you get these kinds of timeouts when controlling a string of AX-12s? I'm trying to figure out if it is really a CM-5 problem or a problem with the Forest Moon library. I have already tweaked the FM library to echo back the servo ID that the timeout occurs on and there does not seem to be any consistent pattern. (I have 11 servos on my bus).

MikeG
05-10-2010, 06:43 PM
To enter toss mode, send a "t" and a CR (0x0D) after entering manage mode on the CM-5.

Download the binaries on http://www.agaverobotics.com/services/dotnet/Dynamixel/default.aspx, setup the CM-5 in manage mode, enter a "t" in the the Raw Command field, and click the lighting bolt. That will put you in toss mode, click away.

To run a test, just wire up a method to the "scroll with a green arrow" button (DynamixelPacketTester project). Also, take a look at the source code, there an example.

You really should be logging the instruction/status packets. That would give you more bang for the buck. Why are you going through the CM-5?

Pi Robot
05-10-2010, 10:09 PM
Thanks Mike, this is great. I am able to use your packet tester binary fine when in TTL mode, but I can't seem to get toss mode working in RS-232 mode. (I am using the LED on/off button as a test.) First I enter a "t" (without the quotes) in the command box and click on the lightning bolt. But then it's not clear what to enter for a carriage return. You write "0x0D" but entering that in the command box (without the quotes again) and clicking the lightning bolt causes the packet tester to crash. If I just enter the "t", I can't turn LEDs on and off.

--patrick

MikeG
05-10-2010, 10:39 PM
Right just enter a "t" and click the button to enter toss mode. I modified the exe to give give you a response that you're in toss mode. No need to enter a 0x0D, I'm doing that in the code which is open source, by the way. There's also a help button, with sample instructions.

The packet tester is just a simple win form that shows how to use Dynamixel.dll. It assumes that you know a little about Dynamixel instructions and I'm not validating extensively.

Pi Robot
05-11-2010, 08:33 AM
I downloaded your updated binary and now I see the "Toss Mode" message when I enter a "t" in the command box. However, I'm still not getting any servo control in toss mode. When I click the lightning bolt icon to enter the "t" command, I do see the send/receive lights on the CM-5 blink once each. But I cannot turn on any LEDs and Pinging a servo sends the command but does not get anything back. I am connecting to the CM-5 at 57600 baud. As soon as I switch the USB2Dynamixel back to TTL mode and reconnect accordingly, everything works OK.

MikeG
05-11-2010, 08:18 PM
Sorry, gave you the wrong dll. That should not have stopped you from controlling a servo though. Anyway, this one will display everything going through the serial port.
http://www.agaverobotics.com/services/dotnet/Dynamixel/source/DynamixelPacketTester.zip

The other dll dispatches status packets messages to the appropriate Dynamixel instance.

Pi Robot
05-12-2010, 09:15 AM
Thanks for the new DLL but still no luck. When I enter toss mode, I get the following messages:

Toss Mode
--> 00
--> 00

If I try to turn on the LED of servo 1 (for example), I get:

--> FF FF 01 04 03 19 01 DD
--> 00
--> 00
--> 00
--> 00
--> 00
--> 00
--> 00
--> 00

So I fired up the Forest Moon Dynamixel Commander program and it connected fine. Then I closed it and brought up the Packet Tester again, and it worked! So it seems your method for entering toss mode might not be working.

MikeG
05-12-2010, 09:47 AM
As I explained, you have to place the CM-5 in manage mode first!

Pi Robot
05-12-2010, 10:52 AM
As I explained, you have to place the CM-5 in manage mode first!

I always do. And the Forest Moon library has no trouble entering Toss Mode. Of course, there is probably still something I am doing wrong. I assume you have a CM-5 and it is working fine at your end? I have a second CM-5 I'll try tomorrow.

MikeG
05-12-2010, 11:20 AM
The display you posted is exactly what happens when the manage LED is blinking when you send the "t". The order is

1) Open the port
2) Place the CM-5 in manage mode - The manage LED is solid
3) Send "t"

Yes, I have a CM-5 and yes it enters toss mode no problem.

Pi Robot
05-12-2010, 11:48 AM
Thanks Mike. Yes, apparently I am missing critical Step 2. I thought the "t" meant that the command was putting the CM-5 in toss mode. With the Forest Moon library, I press the CM-5 red button until the manage LED is blinking. Then the FM library does some things to turn it solid so I don't have to do anything. So how are you putting your CM-5 in toss mode?

Thanks!

MikeG
05-12-2010, 01:04 PM
Like I said, you simply send t<cr> while in manage mode. I followed this method because that's how the Robot Terminal works. If you want to start with the manage LED blinking (selection mode) then send <cr>t<cr>. The first <cr> goes from selection mode to management mode. The next t<cr> enters toss mode.

I modified DynamixelPacketTester and added a "T" button in the toolbar. Clicking the "T" button will enter toss mode if the manage LED is blinking or solid. Be careful, if program or play are flashing, the CM-5 with enter the selected mode. The Forest Moon app will throw an exception and ask you to select manage mode.

I can't stress enough that my code and the Forest Moon code is open source. If you took a few minutes to look at the code, I think you could have figured this out on your own. Another thing to take note, is my code uses threading. I'm handling the status packets with the DataReceived event the Forest Moon code polls the serial port after an instruction.

With my stuff, sending is disconnected from receiving which could make the code a little hard to follow at first. When a status packet is received, the packet is forwarded to a status packet subscriber for processing. There's still some work to be done on the messaging router.

Pi Robot
05-12-2010, 01:07 PM
Thanks for all your help. I'll turn to the source code if I have any more trouble!

MikeG
05-12-2010, 01:58 PM
Sounds good, let me know if you have any question about the source code.