In this section you can find code examples for a first simple program to test your environment and get familiar with it. This code will let your vehicles drive in a circle (not attached to the map)
The code also includes a possible solution to drive a figure eight in the comments.
Procedure:
- Write your code in C++ or Matlab
- Compile it, if you use C++
- Upload it to the LCC (see here)
- Press "deploy"
You define the position of the target points, the speed of your vehicle for each section and the time the vehicle needs to pass a segment. In this example the target points are not connected to the map.
Source Code explanation:
This vector defines the x position of a target point (m):
vector<double> trajectory_px = vector<double>{ 1, 0, -1, 0}
This vector defines the y position of a target point (m):
vector<double> trajectory_py = vector<double>{ 0, 1, 0, -1}
This vector defines the x speed to the target point. The sign gives the orientation in the cartesian coordinate system (unit (m/s)):
vector<double> trajectory_vx = vector<double>{ 0, -1, 0, 1}
This vector defines the y speed to the target point. The sign gives the orientation in the cartesian coordinate system (unit (m/s)):
vector<double> trajectory_vy = vector<double>{ 1, 0, -1, 0}
This vector defines the time the vehicle takes between two target points (unit ns):
vector<uint64_t> segment_duration = vector<uint64_t>{1550000000ull, 1550000000ull, 1550000000ull, 1550000000ull}
In this vector we see the time for 1 m/s and a way length of pi/2 (a quater circle ;))
Advice for use:
- Speed, time and waylength have to fit. Verify your speed/way/duration with vges =s/t
- Remember that vges = sqrt(vx^2 +vy^2) as it is a vector ((here vges,1 = vx,1,-vy,1))
- The vector of the startpoint and the endpoint have to fit (means the tangent has to fit)
(the tangent has the same slope as vector vges,2)
C++
Circular trajectory generation for one vehicle
MATLAB
Circular trajectory generation for one vehicle