Cone's global position

Hello,

I was working on fs_autonomous and to validate our algorithm I need to have the global co-ordinates of the cones, but from what I understood, the position of the cones are defined with respect to the defined route rather than position in a global frame.
Is there a way possible through which I can get the position of the cones in the global frame?

Thank you

Hello,

The cones in the simulation are actually traffic objects that are stationary. The following values can get the global XYZ and rotation angles of a traffic object:

Traffic.<traffic_object_name>.tx
Traffic.<traffic_object_name>.ty
Traffic.<traffic_object_name>.tz
Traffic.<traffic_object_name>.rx
Traffic.<traffic_object_name>.ry
Traffic.<traffic_object_name>.rz

You have to know which cone you are interested in. Their names should be available through the traffic tab in the CarMaker main window and then the Parameters menu.

Since the position of the cones is set by offset to the Route 0, the global position in terms of tx, ty and tz is not available. Is there any way to obtain these?

Hello,

I am sorry for the delay in reply. Hopefully the answer below could be useful to people in the future.

Yes, it seems that for static objects, the location is not calculated as part of the simulation. That is perhaps done to save resources as static objects do not need an updated XYZ at every cycle.

One way to obtain the location of static objects is by reading their s-t position from the current TestRun infofile.

These are set here in the GUI but can also be read from the infofile of the testrun. There are access functions to do that, let me know if you need any help to find them.

To then convert an s-t point to a global XYZ position, the CarMaker ROAD API has to be used. There is a very similar example to this one in the Programmer’s Guide, but I have also created one better-suited to this question. The following piece of code executes once and shows how to use the RoadRouteEval function to convert ST to XYZ points from a specific route. This can be called for the starting position of the cones to get their XYZ global coordinates.

In the future, if this is useful, I can add it to the FSAI package for Formula Student.

// Create a new tRoad object and load the road from the current infofile in it
tRoad* ipg_road = RoadNew();
RoadReadInf(ipg_road, SimCore.TestRun.Inf);

tRoadRouteIn rIn;
tRoadRouteOut rOut;
tRoadEval *ipg_road_RE;

// This is a test point used to demonstrate the RoadRouteEval method
rIn.st[0] = 75.00;
rIn.st[1] = -2.25;

ipg_road_RE = RoadNewRoadEval(ipg_road, ROAD_BUMP_ALL, ROAD_OT_MIN, NULL);
RoadEvalSetRouteByName (ipg_road_RE, "ReverseRoute", 1);

RoadRouteEval(ipg_road_RE, "RoadConversion", RIT_ST, &rIn, &rOut);

Log("Location ST: %f, %f\n", rIn.st[0], rIn.st[1]);
Log("Location XY: %f, %f\n", rOut.xyz[0], rOut.xyz[1]);
1 Like

Thank you bogomil, can you tell me how to use this code snippet?

Hello,

This is example C code that can be used directly inside any plugin developed for IPG CarMaker.

As this code is only required for stationary traffic objects, it should really be executed only once per simulation. I would recommend placing it in a function that executes once at the beginning of the simulation. A good function is “User_TestRun_Start_atBegin” that is already available to CarMaker plugins.

You could either use the “User_TestRun_Start_atBegin” inside User.c of a CarMaker project, or if this is regarding the FSAI competition, the CarMaker ROS node has its own “CMNodeHelloCM::userTestrunStartAtBegin()” C++ method.

I can now see the converted coordinates in the logs. Thanks for the help!