PDA

View Full Version : [Question(s)] A question about Arbotix python library

zzl1007
11-16-2010, 12:35 PM
Hi Fergs,

My name is Xi and i'm a graduate student of electrical engineering. I'm now trying to mimic Patrick's Pi Robot's objecting tracking head part, using the Arbotix micro-controller. But i encounter some questions and would really appreciate it if you can give me some advice.

First, I have downloaded the Arbotix python library. And i also have successfully uploaded the sketch "ros.pde" to my Arbotix board. However, when i run the python code "arbotix.py", it doesn't work.

Here is the error:

>>>

Testing arbotix.py

Traceback (most recent call last):

File "C:\Documents and Settings\ee_admin\Desktop\arbotix-0013\pypose\arbotix.py", line 365, in <module>

d = ArbotiX(sys.argv[1]) # open a port

IndexError: list index out of range

So i browse the code, and made 2 changes:

1. I change the port name in __init__ to "COM3" which is the port in my case. (i have used a FTDI to USB converter)

2. I have deleted the "sys.argv[1]" in the last paragraph and leave it as: d = Arbotix(). Because after i type "print sys.argv", i just get the path of the Arbotix.py file.

Then after i run my revised version, the error changed. Now it is:

Traceback (most recent call last):

File "C:\Documents and Settings\ee_admin\Desktop\arbotix-0013\pypose\arbotix.py", line 365, in <module>

d = ArbotiX() # open a port

File "C:\Documents and Settings\ee_admin\Desktop\arbotix-0013\pypose\arbotix.py", line 55, in __init__

self.ser.open()

File "C:\Python26\lib\site-packages\serial\serialwin32.py", line 56, in open

raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError()))

SerialException: could not open port COM3: [Error 5] Access is denied.

Now it seems that it can recognize COM3, but cannot use it. Then i restart everything, and rerun my revised code again, however, it is running without any error. But nothing can be read from the servo. The prompt is like this:

Testing arbotix.py

Read Failed: Servo ID = 1

-1

Then i run this again, the previous error comes back again.

I have asked Patrick and he said you are the expert of Arbotix. I would really appreciat it if you can provide any suggestion to me.

Thank you so much.

Xi

lnxfergy
11-16-2010, 01:10 PM
Traceback (most recent call last):

File "C:\Documents and Settings\ee_admin\Desktop\arbotix-0013\pypose\arbotix.py", line 365, in <module>

d = ArbotiX(sys.argv[1]) # open a port

IndexError: list index out of range

It's expecting that you would give the port name as a parameter. So at the prompt you would have something like: ./arbotix.py /dev/ttyUSB0, however, I've been told this doesn't always work under Windows.

Now it seems that it can recognize COM3, but cannot use it. Then i restart everything, and rerun my revised code again, however, it is running without any error. But nothing can be read from the servo. The prompt is like this:

Testing arbotix.py

Read Failed: Servo ID = 1

-1

Then i run this again, the previous error comes back again. This combination of "can't open port, then can't read from it" looks like a Windows issue -- the ROS stuff hasn't been tested under windows (as ROS is primarily linux-based). I know we had an issue in another project where it worked under Linux/OSX but failed to open the port under Windows -- this may be the same case. I'll see if I can dig out what the issue was, and if that same issue is here (it had to do with some combo of serial.Serial() and open() causing it to try and re-open the port, but I don't recall what the final version was that worked).

-Fergs

zzl1007
11-17-2010, 03:58 PM
Hi Fergs,

Since you said it seemed like a Windows issue, i have installed Ubuntu 10.4 and try to run the arbotix.py again. However, the exact same error exists. So it might not be a Windows issue.

Xi

lnxfergy
11-17-2010, 04:05 PM
Hi Fergs,

Since you said it seemed like a Windows issue, i have installed Ubuntu 10.4 and try to run the arbotix.py again. However, the exact same error exists. So it might not be a Windows issue.

Xi

Try removing the reset jumper on the ArbotiX -- opening the port would reset the board, and it may be that it hasn't come back fully in time to respond to the reads. (I haven't run that test code in a very long time, and it definitely was on a board without a reset jumper).

-Fergs

Pi Robot
11-17-2010, 07:50 PM
Hi Fergs,

Since you said it seemed like a Windows issue, i have installed Ubuntu 10.4 and try to run the arbotix.py again. However, the exact same error exists. So it might not be a Windows issue.

Xi

Hi Xi and Fergs,

Sorry I am late to this discussion--been swamped at work and running against a grant proposal deadline. Anyway, I finally had a chance to try running the default arbotix.py file in release 0.3.2 under Ubuntu 10.04 and I can duplicate Xi's results exactly. Xi, to fix it, all I had to do was put a small delay between the opening of the port and the first call to the servos. So, out of the box, the end of arbotix.py looks like this:

if __name__ == "__main__":
# some simple testing
print "Testing arbotix.py"
d = ArbotiX(sys.argv[1]) # open a port
d.setPosition(1,512)
print d.getPosition(1)As you noted, change the open port line to:

d = ArbotiX()

And check your port and baud rate settings near the top of the file.

But now also add a sleep line after that one:

time.sleep(1) # sleep one second to give the Arbotix time to wake up

So the final block looks like this:

if __name__ == "__main__":
# some simple testing
print "Testing arbotix.py"
d = ArbotiX() # open a port
time.sleep(1)
d.setPosition(1,512)
print d.getPosition(1)Let me know how it goes!

--patrick

zzl1007
11-18-2010, 04:58 PM
So the final block looks like this:

if __name__ == "__main__":
# some simple testing
print "Testing arbotix.py"
d = ArbotiX() # open a port
time.sleep(1)
d.setPosition(1,512)
print d.getPosition(1)Let me know how it goes!

--patrick[/quote]

Hi Patrik and Fergs,

I have added the time.sleep into the code, i have changed the port back to /dev/ttyUSB0. I have double-checked the GRN and BLK line-up, also the 38400 baud rate, i have even tried the 57600 baud rate you mentioned. There is no error. However, nothing can still be read. After i type "python arbotix.py" in terminal, the same thing still shows up:

Testing arbotix.py
Read Failed: Servo ID = 1
-1

This is really not making sense, cause i think i have the exact same setting with you.

Thanks,
Xi

lnxfergy
11-18-2010, 04:59 PM
You do have an AX-12 with ID #1 attached to the dynamixel bus, right?

-Fergs

Pi Robot
11-18-2010, 05:52 PM
You do have an AX-12 with ID #1 attached to the dynamixel bus, right?

-Fergs

I was just going to ask the same question. I have my ArbotiX hooked up as we speak using the FTDI cable to a USB port on my Ubuntu 10.04 machine. I can get Xi's error two ways: (1) specify a servo ID that I don't have which yields the following for non-existent servo ID 11:

Read Failed: Servo ID = 11
-1

and (2) use an invalid baud rate. For example, my ArbotiX is set for 57600 so if I use 38400 (but set my servo ID back to 1 which is valid) I get:

Read Failed: Servo ID = 1
-1

Note that I get the Fail Read *twice* when the baud rate is wrong which looks more like your situation.

--patrick

zzl1007
11-18-2010, 09:46 PM
Patrick and Fergs,

I think I have connected the ID #17 servo to the arbotix. So why does it say Servo ID = 1, not 17? I will double check tomorrow. By the way, where can you specify the ID of the servo in the program? And this error will occur if you specify a certain ID servo, but connect a different ID one, right?

Xi

lnxfergy
11-18-2010, 10:49 PM
Patrick and Fergs,

I think I have connected the ID #17 servo to the arbotix. So why does it say Servo ID = 1, not 17? I will double check tomorrow. By the way, where can you specify the ID of the servo in the program? And this error will occur if you specify a certain ID servo, but connect a different ID one, right?

Xi

That brief test program sets the position of servo 1, then reads it back (setPosition(servo_id, position) and getPosition(servo_id) are the two functions called). The python backend is really not documented, other than in the code itself (every function should have a pretty explanatory comment though).

The intended usage is through the ROS API, not the python API. The ROS API is pretty well documented on the ROS wiki.

-Fergs

zzl1007
11-19-2010, 12:11 PM
Fergs and Patrick,

Now i know where i should set the ID of the servo(it is the index value right?). I have connected the ID #1 servo instead of my #17. And i have removed the reset jumper J2. Now if i press the reset button, then run the arbotix.py again, it can read the current position now. The output is:

[email protected]:~/Desktop/Pi$python arbotix.py Testing arbotix.py Fail Read 588 However, it still cannot set the servo to the desired position. And if i run the program again, the same error comes back. Nothing can be read. So i must press the reset button every time to get the reading of the position. So any idea what is going on there? Xi DresnerRobotics 11-24-2010, 12:10 PM Mon 11/22/2010 12:28 PM zzl1007 Posted: Patrick and Fergs, I think the arbotix.py is working now. I successfully made the servo spin once: print "Testing arbotix.py" d = ArbotiX() # open a port time.sleep(1) d.setPosition(1,600) print d.getPosition(1) And the output is [email protected]:~/Desktop/Pi$ python arbotix.py
Testing arbotix.py
600

However, if i set the desired position to some other values, e.g., 700 or 300, it wouldn't work. The output is
Testing arbotix.py
Read Failed: Servo ID = 1
-1

So i was wondering, is the angle parameter from 1 to 1024, and 1 means the very beginning position of the servo, and 1024 means the max the servo can go? If that is the case, then any value between 1 and 1024 should work.

Looking forward to your reply and wish you a good Thanks Giving!

Xi

DresnerRobotics
11-24-2010, 12:14 PM
Mon 11/22/2010 12:36 PM
zzl1007 Posted:

Patrick and Ferg,

I have some clues now. If i set the new position within the difference of 10 compare to the old one, the code will work. So i suppose the change of the position cannot be too large. Or is it just can be 10 in one step? Or is there even a "step"?

Xi

DresnerRobotics
11-24-2010, 01:47 PM
Tue 11/23/2010 9:02 AM
Pi Robot has just posted

Patrick and Ferg,
I have some clues now. If i set the new position within the difference of 25 compare to the old one, the code will work. So i suppose the change of the position cannot be too large. Or is it just can be 25 in one step? Or is there even a "step"?

Xi

Hi Xi,
That is very strange. I am sitting at my robot now and the following works fine on my ArbotiX with my head pan servo which is ID 1.

Code:
---------
print "Testing arbotix.py"
d = ArbotiX() # open a port
time.sleep(1)
start = 512
end = 800
step = 5
d.setSpeed(1, 100)
d.setPosition(1, start)
time.sleep(2)
d.setSpeed(1, 800)
for position in range(start, end, step):
d.setPosition(1, position)
time.sleep(0.02)
---------

I am connected by way of the FTDI break out on /dev/ttyUSB0. The result is a smooth panning motion from the start position to the end position.

--patrick

DresnerRobotics
11-24-2010, 01:56 PM
Tue 11/23/2010 10:27 AM
lnxfergy has just posted

What is your power supply? I've seen in the past that a large movement can cause the power to drop, and the AX-12s sometimes fail to respond to queries if they are moving and the power supply can't handle it.

-Fergs

DresnerRobotics
11-24-2010, 01:57 PM
Tue 11/23/2010 11:03 AM
zzl1007 has just posted

Fergs,

My power supply is a adpatable DC votalge source. I have set the voltage to 11.10V according to the manual and the current is 0.4A. Does this seems reasonable?

Xi

DresnerRobotics
11-24-2010, 02:03 PM
Tue 11/23/2010 11:30 AM
zzl1007 has just posted

Hi Xi,
That is very strange. I am sitting at my robot now and the following works fine on my ArbotiX with my head pan servo which is ID 1.

Code:
---------
print "Testing arbotix.py"
d = ArbotiX() # open a port
time.sleep(1)
start = 512
end = 800
step = 5
d.setSpeed(1, 100)
d.setPosition(1, start)
time.sleep(2)
d.setSpeed(1, 800)
for position in range(start, end, step):
d.setPosition(1, position)
time.sleep(0.02)
---------
I am connected by way of the FTDI break out on /dev/ttyUSB0. The result is a smooth panning motion from the start position to the end position.

--patrick

Patrick,

If you set the step to 40 instead of 5, will it still work? Your code can work on me too but if i set the step too large, it will fail.

Xi

DresnerRobotics
11-24-2010, 02:06 PM
Tue 11/23/2010 12:16 PM
lnxfergy has just posted

Fergs,

My power supply is a adpatable DC voltage source. I have set the voltage to 11.10V according to the manual and the current is 0.4A. Does this seems reasonable?

Xi

Stall current is [email protected] -- so conceivably, at lower voltage (higher current) the moving current could spike above 0.4A
-Fergs

DresnerRobotics
11-24-2010, 02:18 PM
Tue 11/23/2010 2:39 PM
zzl1007 has just posted

Stall current is [email protected] -- so conceivably, at lower voltage (higher current) the moving current could spike above 0.4A
-Fergs

Fergs,

I have increased the current to 1A. And everything is working fine. Thank you for the help.:veryhappy:

Xi