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

why cannot use tf::Quaternion and tf::createQuaternionMsgfromYaw in arduino

asked 2017-01-07 00:25:45 -0500

shawnysh gravatar image

updated 2017-01-09 00:29:58 -0500

I try to use tf::Quaternion and tf::createQuaternionMsgfromYaw in arduino

I have included ros.h and tf/transform_broadcaster.h

but when I build the code in arduino ide , it shows error:

> error: 'createQuaternionMsgFromYaw' is not a member of 'tf' error:
> error:'Quaternion' is not a member of 'tf'

I want to send transform on arduino, reference to official tutorial:Writing a tf broadcaster , using urdf with robot_state_publisher, and using time and tf on the arduino

I get data from robot, which stored in struct ArmData on arduino, including absolute positions and joint angles, and I want to publish joint_state and send transform to ros through rosserial_arduino.

when updating joint_state, I find that I cannot use resize() method, the way in tutorial using urdf with robot_state_publisher, since I do not install string lib on arudino ide. Is it neccesary to do so? Or, there is another way to substitute it using arduino code?

Is there any suggestion to code what I want to do on arduino? Thanks!

Here is part of my code with regard to update the joint_state and transform:

    geometry_msgs::TransformStamped ts;
    const double d2r=1000/57296; //turn degrees to radians

//update transform from odom to base_link

  //update joint_state;

  //send the joint state to topic /joint_states
  //send transform

Edit1: Thanks for ahendrix's advice, I take a look at rosserialOverviewMessages

and modify my code according to what this tutorial does

But error occurs unfortunately.

    ros_dobot_arduino:93: error: 'jstate' does not name a type;
ros_dobot_arduino:95: error: 'jstate' does not name a type
exit status 1
'jstate' does not name`enter code here` a type

It seems like sensor_msgs::JointState object does not have the methods which tutorial shows?


#include <ros.h>
#include <sensor_msgs/JointState.h>
#include <ros/time.h>
#include <tf/tf.h>
#include <tf/transform_broadcaster.h>
#include <pt.h>   // include protothread library

The above are what I have included in Arduino code


I have founded where the problem was.

It was because I assign value to rosserial msg before setup() function, which means the nodehandle has not yet been initialized!

I think, due to this, rosserial msg can not be used, right? If so, I want to know why needs a nodehandle, I just assgin a value to msg object?

At first, I want to pre-assign value to some msg because joint name did not ... (more)

edit retag flag offensive close merge delete


Please note that Atmel AVRs do not have a floating point unit. And doing 32/64 bit floating point operation on an 8 bit device without FPU is not recommended. I would send the Odometry as yaw only and do the conversion on the PC.

Humpelstilzchen gravatar image Humpelstilzchen  ( 2017-01-09 04:42:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-07 00:43:44 -0500

ahendrix gravatar image

updated 2017-01-09 00:45:59 -0500

rosserial_arduino is NOT a full-featured ROS installation, so there are many features that don't work for the Arduino, and many things that are different.

In general, tutorials that describe standard ROS features do not apply to the Arduino.

In particular, array messages are raw C arrays; not vectors. Have a look at the rosserial Messages description, which shows how to properly initialize a JointState message on the arduino.

I don't see it in the documentation, but I believe that in order to get tf::createQuaternionFromYaw, you need to #include <tf/tf.h>


It looks like you've made progress. You don't show the includes that you're using, but since the compiler is complaining about jstate it seems like you haven't included the header for the joint state message either. You probably need #include <sensor_msgs/JointState.h>


You don't need to initialize your messages and your NodeHandle in a particular order, but the message initialization does need to happen inside a function. You can have variable declarations outside a function, but you can't have other statements outside of a function. (This is a general rule in C and C++; not specific to rosserial or Arduino)

edit flag offensive delete link more


I used tf::createQuaternionMsgFromYaw because I saw it in tutorial for urdf and I checked it in tf namespace reference, I think this tf reference is for roscpp only instead of arduino, right?

shawnysh gravatar image shawnysh  ( 2017-01-08 06:25:05 -0500 )edit

So, I should check it in rosserial API document, right? Thanks

shawnysh gravatar image shawnysh  ( 2017-01-08 06:25:53 -0500 )edit

Yes; the tf namespace reference only applies to roscpp. Unfortunately I think the rosserial API docs are incomplete, and they haven't documented tf::createQuaternionMsgFromYaw, even though it exists in rosserial_arduino

ahendrix gravatar image ahendrix  ( 2017-01-08 13:25:00 -0500 )edit

omg, not documented yet?

shawnysh gravatar image shawnysh  ( 2017-01-08 19:52:26 -0500 )edit

Question Tools

1 follower


Asked: 2017-01-07 00:25:45 -0500

Seen: 5,535 times

Last updated: Jan 09 '17