Get velocity of car with CMRosIF

I want to use a Carmaker Simulation to control the speed and other parameter of a simulator consisting of a treadmill and a vehicle. They are communicating over ROS. Therefore I want to get velocity and other parameters from CarMaker to an extern node. I made the changes to publish the velocity value in the CMNode_ROS1_HelloCM.cpp-file in the hellocm_cmnode folder(carmaker ros node). But I don’t know how to insert the user specific funtions of this file into the main method of my hellocm-node(extern Ros node). What do I have to change in order to use the init-function of my CMNode_ROS1_HelloCM.cpp-file with the changes I made?

Hello Fred,
I’ll probably need some clarification here.

If you’ve made the changes to the CMNode_ROS1_HelloCM.cpp node, then ideally you are getting the vehicle velocity published over ROS1 already. Do you get successful publishing of velocity messages? Which message type are you using here, is it a standard basic twist command, or a custom message?

Exactly, I simply added a variable (velocity) to the CM2Ext.msg file. In the CMNode_ROS1_HelloCM.cpp I stored the variable I want to publish (Car.ConBdy1.v) in a new variable and added this with (out->Msg.longVel = velocity) to the message I want to publish. But when I look at the messages over rqt, the value of longVel is always 0.0, but over DirectVariableAccess one can find that it’s not.
Additionally, I don’t understand how my function should even get executed in the main function of my HelloCM-Node. So I need to write a header file for my CMNode_ROS1_HelloCM.cpp and include this in the ROS1_HelloCM.cpp and change the init function used?
Thank U very much

Hi Fred,

First thing to check is whether the CM2Ext.msg in RQT changes at all. Both the cycleno or the time field of the message should hopefully increase as the simulation progresses. If they don’t, then we know the message is not properly updated and published at all for some reason.

The second thing is to make sure that the added variable “velocity” is actually updated as well at every CarMaker cycle. Maybe you can try to cut out the middle man while testing and directly plug out->Msg.longVel = Car,CinBdy1.v

The last thing is the HelloCM-Node connection. The connection is already made over ROS1, so adding the header of the CMNode is not needed. I think what you are talking about is already handled by the CarMaker-ROS interface libraries that my colleagues in Germany have written in the past. HelloCM-Node creates a subscriber to the CM2Ext message already. The “tRosIF_TpcSub” function is part of the custom internal CMRosIF functions which automatically creates the said subscriber. It is being pointed to the correct topic name (RosIF.Topics.Sub.CM2Ext.Sub = node->subscribe(hellocm::tpc_in_name, 10, ros_HelloCM_CB_TpcIn); )

With the current setup, every time HelloCM-Node receives a CMExt message on the desired topic, it will trigger the “ros_HelloCM_CB_TpcIn” callback (this is specified above in the node->subscribe, this is where you can change the callback as well if you want). This also conforms to the usual ROS practices where nodes are independent, HelloCM-Node doesn’t know that another node called CMNode exists, it simply listens for a specific ROS message over a specific ROS topic and executes the given callback when this message is heard.

Hopefully that helps a bit!

Thank you, as soon s possible, I will look at the messages to see whether they are published at all.
What bothered me as well were the LOGs. In the CMRosIF_CMNode_Out() function, I added a Log entry, but I never saw this one in the Log-files. This should point out, that the function in not called and therefore, my variable not added to the job, or am I wrong? The log-files only show the Logs from the init-function of the Ros-Node, but none of the CarMaker-Ros-Node.
Do you have an idea where this could come from or what could be the issue here?
Thank you already!

Hi Fred,

Before you made any changes, was the project running? Was the CM2Ext.msg message being transmitted successfully before any changes were made?

It looks like the CMNode_ROS1_HelloCM may not be running at all. You can confirm that if you start RQT Node Graph. Do you see a node called “CMNode” there?