You find the source code for our examples in the software-folder:
One vehicle drives a line on the ground, unattatched of the map. The supporting points are x = ( 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0) and y = (-1, -1, -1, -1, -1, -1, -1, -1, -1). These points are centered are around (x,y) = (0, 2).
Define the ID of the vehicle you want to drive. Read the ID in from the LCC using the function cmd_parameter_ints() from our cpm library.
Initialize a DDS Writer for the RTI DDS Service to ensure that position and speed will be sent to the simulation and the vehicle. Write on the topic
vehicleCommandTrajectory with datatype
VehicleCommandTrajectory. The topic's name is the name of the datatype with a lowercase letter.
In the C++ version start a timer using cpm::Timer.
Giving direction, speed and timestamp
Define your trajectory points for x and y according to the goal of this tutorial.
Define your speed in x direction and y direction. In this case the speed in x direction is the maximum speed of 1 m/s and in y direction 0 m/s.
Define the timestamp. Start at
t_now and then add your
segment_duration for the first step, always considering the previous step for interpolation.
Sending the trajectory information to the vehicle
All data are sent to the vehicle using the writer-function from the beginning in the form of
where each value is a scalar.
Run the example
- Compile your code.
- Upload it in the LCC.
- Select e.g. vehicle 1 (simulated mode).
- Hit "Deploy" and wait. You will see a trail which builds and erases from point to point. This is your trajectory. Now "kill" your program. Move the simulated vehicle close to the trajectory by dragging it to a close point to the line trajectory. A trail will be drawn which is the trajectory for your vehicle to get the line trajectory.
- Once the vehicle is close to the trajectory starting point "deploy" your program again. The vehicle will drive on your trajectory.
- To end the program hit "Kill".