ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Rosserial help

asked 2012-03-27 12:56:21 -0600

allenh1 gravatar image

There is something wrong. I have no idea what. Anybody who knows what this is willing to help?

Here is the code from the arduino:

#include ros.h
#include <std_msgs/String.h>
#include <std_msgs/Float64.h>
#include <sensor_msgs/Imu.h>

ros::NodeHandle  nh;

sensor_msgs::Imu data;
ros::Publisher p("imu", &data);

char frame[] = "/imu";

int xPin = A0;
int yPin = A1; 
double xValue = 0;
int xValueRaw = 0;
double yValue = 0;
int yValueRaw = 0; 

void setup()
{
  nh.initNode();
  nh.advertise(p);
}

void loop() {
  // read the value from the sensor:
  xValueRaw = analogRead(xPin);   
  xValue = (((xValueRaw *  0.0049) - 1.66) / (0.312)) * 9.80665; //convert to m / s^2
  yValueRaw = analogRead(yPin);
  yValue = (((yValueRaw *  0.0049) - 1.66) / (0.312)) * 9.80665; 
  //convert to volts<

  //now, we publish the m/s^2 acceleration to ROS. 

  data.header.frame_id = frame;
  data.orientation_covariance[0] = -1; //tells ROS  to ignore the orientaiton of the data (not provided)
  data.angular_velocity_covariance[0] = -1; //tells ROS to ignore the angular velocity of the data (not provided)
  data.linear_acceleration.x = xValue;
  data.linear_acceleration.y = yValue;
  data.linear_acceleration.z = 0; 

  data.header.stamp = nh.now();
  p.publish(&data);
  nh.spinOnce();
  delay(250);
}

I chose a low publish speed just for the purpose of checking that I'm getting something. Unfortunately, rosserial is giving me this:

turtlebot@Turtlebot_0356:~$ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=4 
[INFO] [WallTime: 1332888473.566842] ROS Serial Python Node
[INFO] [WallTime: 1332888473.582473] Connected on /dev/ttyACM0 at 4 baud
Traceback (most recent call last):
  File "/opt/ros/electric/stacks/rosserial/rosserial_python/nodes/serial_node.py", line 56, in <module>
    client = SerialClient(port_name, baud)
  File "/opt/ros/electric/stacks/rosserial/rosserial_python/src/rosserial_python/SerialClient.py", line 242, in __init__
    self.requestTopics()
  File "/opt/ros/electric/stacks/rosserial/rosserial_python/src/rosserial_python/SerialClient.py", line 246, in requestTopics
    self.port.flushInput()
  File "/usr/lib/python2.6/dist-packages/serial/serialposix.py", line 358, in flushInput
    raise portNotOpenError
serial.serialutil.SerialException: Port not open

I am not sure why it doesn't like me, but it really doesn't. I don't know how baud rates work, so I chose 4 because it should send 4 messages in one second. Please help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-03-27 17:01:27 -0600

Dustin gravatar image

The baud rate determines how much data can be transmitted per second, it does not dictate how many messages must be sent per second. That is the purpose of the delay you specified. I believe the default baud rate for rosserial is 57600 but if you don't specify it then the python node will use the correct value. I believe things will work correctly if you use the following command:

rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0
edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-03-27 12:56:21 -0600

Seen: 1,445 times

Last updated: Mar 27 '12