Car state (position and velocity) using ros

How to get the car state (position and velocity) using ros and the example of formula car
Thanks in advance

Hello Ahmed,

I would highly recommend going through Section 4 of the CMRosIF_UsersGuide_FS_autonomous document supplied with the FSAI package. You can find that information in the following locational at the root of the project: FCM_Projects/FS_autonomous/doc/

The mentioned example goes through the rough locations in the C++ code of the CarMaker ROS node that need to be amended in order to publish an additional signal. Roughly these are:

  1. Create your own ROS message or use an existing ROS message that supplies position and velocity. Include the header describing the message in the C++ code.
  2. Create a publisher object and store it, preferably in the existing structure under Topics.Pub
  3. Advertise the topic and create a publishing job which would publish data periodically.
  4. Initialise the job
  5. Copy relevant CarMaker data into the job
  6. Publish the job

This sounds lengthy, but the example points to exact locations in the code where other publishers show how it’s done.

I believe the relevant signals for the car state that you have asked for are known inside CarMaker as:
Car.v (can be split into Car.vx, Car.vy, Car.vz) as well as Car.tx, Car.ty,

Hope that helps.

1 Like

Thank you for your effort and for the response.

I had done all what section 4 says and I have successfully published new data but there were an issue.

I had to add the Inertial sensor to get the velocity and position of the car, The inertial sensor has an issue that every time I save and start car maker there is an error occurs and says "CMNODE : Error on DoPrep for Job 'my job name ’ rv = Evrlln

And I have included every thing I need for Inertial sensor as Vehicle/Sensor_Inerial.h and I have added a struct of Inertial sensor in the Sensor struct

I hope to hear from you very soon as I have been stuck here for a while

Thanks in advance

Hello Ahmed,

I’m happy to help figure out what’s wrong with the inertial sensor. However, before we dive into that, I wanted to perhaps suggest an easier approach with fewer code modifications.

Car position and velocity should technically be available without querying the inertial sensor. They would be found inside Car.h from the CarMaker native header files. Would it be simpler to get these values rather than from the inertial sensor?

Regarding the error you are getting, is ‘my job name’ the actual name you have given to this job, or just a placeholder instead of the real name?

I have solved the error of the Inertial sensor

But it will be more helpful if i get the current states from car maker so can you tell me how to do that or is there any documentation that will be helpful

What I have understood that i will include Car.h in my code so what are the values that I should publish

Thanks in advance

Hello Ahmed,

I think the best source of information on this topic would be the CarMaker Reference Manual. More specifically, for your question I would look at “Section 24.5 Vehicle” and “Section 24.7 Car”. The first section corresponds to C quantities available in “Vehicle.h”, and the second corresponds to “Car.h”. It looks like the vehicle state values double up in both of those header files, so either of them may have the required signals from CarMaker directly accessible in C/C++.

For your purposes, the “Name C-Code” is of course the relevant column. I appreciate this table is quite large as there is a lot going on inside Car.h, but the basics of vehicle speed, position, orientation, and all of their relevant derivatives should all be there: