Rosserial help
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!