Results 1 to 7 of 7

Thread: Python Serializer library available

  1. #1
    Join Date
    Apr 2009
    Location
    Stanford, CA USA
    Posts
    590
    Rep Power
    47

    Python Serializer library available

    Folks,

    Inspired by Mike's work on developing an open source Python library and ROS package for the ArbotiX, I put together a Python library for the Robotics Connection Serializer microcontroller. For the most part, the library simply wraps the Serializer's firmware commands so that you can access them from your Python program. However, I have also added some convenience functions such as get_PhidgetsTemperaure() if you have a Phidgets temperature sensor on one of your pins. Similar functions are included for Phidgets Voltage and Current sensors as well as the Ping sonar and Sharp GP2D12 IR range sensors. There are also some special PID functions such as mogo_m_per_s() which allows you to move your drive motors in meters per second if you have your VPID and DPID parameters set up correctly.

    In any event, you can find out more and get the current version from:

    http://www.pirobot.org/code

    There are four example files included with the library to give you an idea how it works.

    Note that I was unable to test a number of functions since I don't have the relevant sensors including:

    * get_maxez1 (for the MaxEZ1 sonar sensor)
    * step (used with a bipolar stepper motor)
    * sweep (also used with a bipolar stepper motor)
    * srf04, srf08 and srf10 (used with a Devantech SRF04, SRF08 and SRF10 sonar sensors)
    * tpa81 (used with the Devantech TPA81 thermopile sensor)
    * line (used with the Robotics Connection line following sensor)

    So if someone can test any of the above, it would be great to hear from you.

    In the meantime, I am working on a ROS package for the Serializer based on this Python library. So far it is working quite well but I still have some more testing to do before it is ready for release.

    --patrick
    The Pi Robot Project
    http://www.pirobot.org

  2. #2

    Re: Python Serializer library available

    Hi Patrick
    I have tried your programs under linux and i have managed to get them to work i'm still tring to sort out my board and robot to get it to work smoothly. get_maxez1 in the examples will freaze the program if get_maxez1 returns NACK(for some reason i get NACK the first try) on the restart it works great
    i tried to use serializer under windows but i get the following error

    Connecting to Serializer on port COM10 ...

    Traceback (most recent call last):
    File "C:\Python26\serializer.py", line 1157, in <module>
    mySerializer.connect()
    File "C:\Python26\serializer.py", line 101, in connect
    test = (self.port.readline(eol='>')[0:-3]).strip()
    TypeError: readline() got an unexpected keyword argument 'eol'

    but since i want to setup this robot under linux(ubuntu 10.4) and ROS. its not a problem
    keep up the good work i have learnt more in the last 2 weeks using pyserializer than in the last year
    i look forward to seeing how to add the serializer to ROS

    regards Peter

  3. #3
    Join Date
    Apr 2009
    Location
    Stanford, CA USA
    Posts
    590
    Rep Power
    47

    Re: Python Serializer library available

    Hi Peter,

    Thanks for the feedback! It looks like readline() was broken in PySerial 2.5 on Windows as I just found out here:

    http://sourceforge.net/tracker/?func...87&atid=446302

    You can fix it by downgrading to PySerial 2.4 on Windows:

    http://sourceforge.net/projects/pyserial/files/

    (I used pyserial-2.4.win32.exe and it made the error go away.)

    I don't have a MaxEZ1 to see if it works now, but if you get the latest release of the pyserializer library, I now have a check for 'NACK' and do a retry until I get a value. I also fixed some bugs in the PID calculations used in functions like travel_distance(). You can get it from:

    http://code.google.com/p/pyserialize...tags/0.2.2/src

    Note that for the PID stuff, you have to set your own parameters near the top of the serializer.py file, then set INIT_PID = True to have them written to your Serializer. It's usually best to put your robot up on blocks when first setting these to avoid having it fly across the room because you have the wrong units or incorrect wheel size, etc. I have the units set to 0 for metric since ROS is all done in meters and radians.

    --patrick
    The Pi Robot Project
    http://www.pirobot.org

  4. #4

    Re: Python Serializer library available

    Hi Patrick
    Thanks for the info on pyserial 2.4 i had to install pywin as well to get it working. Example 1 still stalls on reading a Maxez1 that returns a NACK the error is valueerror invalid literal for int() with base 10: ā€˜Nā€™
    In example 2 the line
    mySerializer.rotate(math.pi * 2, 0.2) # Rotate 90 degrees at speed 0.3 radians per second
    had me stumped how does this equal 90 degrees????? I was getting 270 deg so i changed math.pi*2 to math.radians(90) now the robot turns 90 deg does this seem correct or have i got it wrong??

    Regards peter

  5. #5
    Join Date
    Apr 2009
    Location
    Stanford, CA USA
    Posts
    590
    Rep Power
    47

    Re: Python Serializer library available

    Hi Peter,

    Thanks for the update. I have fixed the travel distance and rotation angle in the example2.py file and updated the Windows requirements on the project page. I was also able to borrow a MaxEZ1 sonar sensor from a friend and I verified that the get_maxez1() function works OK. The problem might be how you have it wired to your Serializer as it took me forever to get it right. Here's a post on the Robotics Connection forum that steered me in the right direction:

    Hello Chad,
    If I follow the Serializer manual properly, the command is
    maxez1 (trigger pin) (output pin) or

    maxez1 (rx) (pw) ( with EZ1 gnd on pin1, +5 on pin2 )
    in my case I use a MaxEZ3 like so:

    S-W/L EZ3
    Port 4 (1) gnd
    Port 4 (2) +5
    Port 4 (3) rx (trigger)
    Port 5 (3) pw (return pulse)

    I hope you get it working,

    robotics.djlewis.us


    Don Lewis
    The full thread can be found here:

    http://www.roboticsconnection.com/us...ghlight=maxez1

    You can test this in a terminal window by issuing the command:

    maxez1 4 5

    If you get back a NACK then the wiring is probably incorrect or the sensor might be damaged. If you always get back 255, then you might have the pin numbers reversed in the command above. Note that if you have an I2C device connected, you cannot using pins 1 and 2 for the MaxEZ1.

    The updated library is at:

    http://code.google.com/p/pyserialize...tags/0.2.3/src

    Let us know how it goes!

    --patrick
    The Pi Robot Project
    http://www.pirobot.org

  6. #6

    Re: Python Serializer library available

    Hi Patrick
    The maxez nack only happens on first run after 2 or 3 tries using a termial it works then works fine the rest of the night and not always the same pins(i have 3 sonars)

    regards peter

  7. #7
    Join Date
    Apr 2009
    Location
    Stanford, CA USA
    Posts
    590
    Rep Power
    47

    Re: Python Serializer library available

    Hey Peter,

    If it takes 2 or 3 times even when using the terminal, you might want to post your issue to the Robotics Connection forum. This is the only time I have tried a MaxEZ1 and it always works the first time for me, both from the terminal and when using the pyserializer library. A few things that come to mind are: what kind of communication are you using (USB, XBee, Bluetooth, RS-232?); what baud rate? and can the RC folks suggest a diagnostic test? I've had one Serializer start to flake out after two years of use and it did so with intermittent communication problems and problems with different pins...

    --patrick
    The Pi Robot Project
    http://www.pirobot.org

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. An robot programming idea in Python
    By Pi Robot in forum Software and Programming
    Replies: 62
    Last Post: 08-23-2010, 06:21 PM
  2. Python version of Forest Moon Dynamixel Library now available
    By Pi Robot in forum Software and Programming
    Replies: 2
    Last Post: 08-11-2010, 04:14 PM
  3. News/Announcement RX-28 and RX-64 Open-Source (Python) Libraries Available
    By hizook in forum Robotics General Discussion
    Replies: 1
    Last Post: 03-19-2010, 10:02 PM
  4. Project Jim and the Serializer - Part 1
    By JimH in forum Arbotix, Microcontrollers, Arduino
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  5. Project Jim and the Serializer - Part 2
    By JimH in forum Arbotix, Microcontrollers, Arduino
    Replies: 5
    Last Post: 02-26-2008, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •