0
$\begingroup$

Rosanswers logo

I'm looking through the rosserial tutorials and the basics are escaping me. Does anyone have an example of python code that connects to a serial port (a linked USB in my case) and sends values to a Microcontroller (BS2 in my case). I'm using the BS2 to actuate a very basic remote controlled arm (OWI Arm Trainer) from an Ubuntu/ROS diamondback laptop. I've been through most of the tutorials but cannot determine a simple way to open the serial port and send values to the BS2. Can someone at least get me started in the right direction?


Originally posted by kleekru on ROS Answers with karma: 71 on 2012-02-23

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

If you are not using rosserial, I would work on getting basic serial communication working outside of ROS first. @kleekru mentioned he is working in Python. I would look at the documentation for pySerial, and figure out how to just send the characters you want to send. For example, the following snippet would send the ascii character for '2' as you requested

import serial
com = serial.Serial('/dev/ttyUSB0',baudrate=115200)
com.write('2')
com.close()

For @nachoarreola, you need to look up termios.h (assuming you are on linux). A bunch of good examples can be found here. Once you understand how to send commands programmatically, you can then write a ROS node that helps you out.

The system I'm currently working with has robots that cannot run ROS onboard. So I have a serial node that advertises a ServiceServer. This serial node is responsible for opening the connection and sending data. When a different node wants to send a serial packet to a robot, it calls the service advertised by the serial node, the serial node assembles the serial packet, sends the data out the serial port, and then replies to the client node with the robot's response.


Originally posted by jarvisschultz with karma: 9031 on 2012-04-18

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

rosrun rosserial_python serial_node.py /dev/ttyUSB0


Originally posted by dornhege with karma: 31395 on 2012-02-24

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by kleekru on 2012-02-24:
Ok, that helps... I'll see if I can dissect these but they are somewhat over my head. To cut to the chase, ...Say I wanted to pass a value to the BS2 like "2". Would I simply add a parameter to the command line or do I need to update the code?

Comment by dornhege on 2012-02-24:
Maybe you are misunderstanding what rosserial is? It's not a serial access library to send characters. It requires a matching firmware on the MC and allows you to publish/subscribe ROS message directly on the MC. If you just want to send chars, you can grab that functionality from the serial_node.py

Comment by kleekru on 2012-02-24:
Thanks Christian... I did have a suspicion I was barking up the wrong tree. I'm not a Python developer but hope to learn more. Would you mind helping me through this? I'll try running serial_node.py against ttyusb0 at 9600 baud and see what happens... But I'm flying blind...

Comment by dornhege on 2012-02-24:
What are you actually trying to achieve? Just for sending bytes manually, you can use something like gtkterm. If you programmatically want to send them from python code, have a look at how the serial_node.py does it in the send() function. Or do you want to run rosserial on your device?

Comment by kleekru on 2012-02-24:
I would prefer to run rosserial on the BS2 but it looks as though that hasn't been done yet. I'm probably not the one to pave new ground without some help but I'm certainly willing to contribute. What I lack in programming experience, I might partially make up for in enthusiasm and attention. For now, I'm building the platform to be completely remote controlled. I have a Roomba with a laptop onboard running Ubuntu/ROS Diamondback with the iRobot SCI cable, and the Roomba_500_series package is being called by some php pages. The laptop is also a webserver so I'm able to run the robot remotely via the internet. I'm using it as a telepresence platform and I would like to add a very simple arm to it and control it via the same web page.

Comment by kleekru on 2012-02-24:
After I get the ARM running, I may want to begin experimenting with more automation, navigation, or add the Kinect for vision & navigation. For now, I just want some clarity on how to leverage ROS to programmatically actuate the ARM. The way I have the ARM and the BS2 is set up now... if I use the PBASIC debug option, I can enter any value 0-9 to actuate one of the ARM joints on the laptop keyboard... but as I mentioned above, I would like to send the commands programatically from a php page.

Comment by kleekru on 2012-02-24:
I was able to install rosserial and run serial_node.py... I added the line send("1")

Comment by dornhege on 2012-02-25:
If you are only interested in sending values 0-9 from python, you won't need rosserial. You can just make up a very simple python script that uses the Serial class. If I interpret the serial_node.py correctly that should about two lines.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.