utils: Doxygen documentation
-
namespace soil_simulator
Functions
-
std::tuple<std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>> CalcBodyCornerPos(std::vector<float> pos, std::vector<float> ori, Body *body)
This function calculates the global position of the six corners of the body.
- Parameters:
pos – Cartesian coordinates of the body origin. [m]
ori – Orientation of the body. [Quaternion]
body – Class that stores information related to the body object.
- Returns:
A tuple composed of six vectors giving the Cartesian coordinates of the body corners in that order: right side of the body joint, left side of the body joint, right side of the body base, left side of the body base, right side of the body teeth, left side of the body teeth. [m]
-
bool CheckBodyMovement(std::vector<float> pos, std::vector<float> ori, Grid grid, Body *body)
This function calculates how far the body has travelled since the last soil update and checks whether it is necessary to update the soil.
This function calculates the maximum distance travelled by any part of the body since the last soil update. The position of the body during the last soil update is stored in the
body
class.If the maximum distance travelled is lower than 50% of the cell size, the function returns
false
otherwise it returnstrue
. Note that if the distance travelled exceeds twice the cell size, a warning is issued to indicate a potential problem with the soil update.- Parameters:
pos – Cartesian coordinates of the body origin. [m]
ori – Orientation of the body. [Quaternion]
grid – Class that stores information related to the simulation grid.
body – Class that stores information related to the body object.
- Returns:
A boolean indicating whether the soil should be updated.
-
std::vector<float> CalcNormal(std::vector<float> a, std::vector<float> b, std::vector<float> c)
This function calculates the unit normal vector of a plane formed by three points using the right-hand rule.
- Parameters:
a – Cartesian coordinates of the first point of the plane. [m]
b – Cartesian coordinates of the second point of the plane. [m]
c – Cartesian coordinates of the third point of the plane. [m]
- Returns:
Unit normal vector of the provided plane. [m]
-
std::vector<float> CalcBodyFramePos(int ii, int jj, float z, Grid grid, Body *body)
This function calculates the position of a considered cell in the body frame assuming that the body is in its reference position.
- Parameters:
ii – Index of the considered cell in the X direction.
jj – Index of the considered cell in the Y direction.
z – Height of the considered position. [m]
grid – Class that stores information related to the simulation grid.
body – Class that stores information related to the body object.
- Returns:
Cartesian coordinates of the considered position in the reference body frame.
-
std::vector<float> CalcRotationQuaternion(std::vector<float> ori, std::vector<float> pos)
This function applies a rotation
ori
to the Cartesian coordinatespos
.The Quaternion convention is used for 3D rotation.
The mathematical reasoning behind this implementation can be easily found in the Wiki page of Quaternion or elsewhere.
- Parameters:
ori – Orientation of the body. [Quaternion]
pos – Cartesian coordinates of one point of the body in its reference pose relative to the body origin. [m]
- Returns:
Rotated Cartesian coordinates of the input
pos
relative to the body origin. [m]
-
std::vector<float> AngleToQuat(std::vector<float> ori)
This function converts Euler angles following the ZYX convention to a quaternion.
The mathematical reasoning behind this implementation can be easily found in the Wiki page of Quaternion or elsewhere.
Note that this function only works if the Euler angles follow the ZYX convention.
- Parameters:
ori – Orientation of the body. [Euler angles, ZYX sequence]
- Returns:
Orientation of the body. [Quaternion]
-
std::vector<float> MultiplyQuaternion(std::vector<float> q1, std::vector<float> q2)
This function calculates the product of two quaternions.
The mathematical reasoning behind this implementation can be easily found in the Wiki page of Quaternion or elsewhere.
- Parameters:
q1 – First quaternion. [Quaternion]
q2 – Second quaternion. [Quaternion]
- Returns:
Product of the two inputs quaternions. [Quaternion]
-
bool CheckVolume(SimOut *sim_out, int init_volume, Grid grid, float tol)
This function checks that the volume of soil is conserved and that the content of
body_soil_pos_
andbody_soil_
is consistent.The initial number of soil cells (
init_volume
) has to be provided. The number of soil cells is used instead of volume in order to avoid issue due to floating number approximation.- Parameters:
sim_out – Class that stores simulation outputs.
init_volume – Initial number of soil cells.
grid – Class that stores information related to the simulation grid.
tol – Small number used to handle numerical approximation errors.
- Returns:
Boolean indicating whether soil is conserved or not.
-
bool CheckSoil(SimOut *sim_out, float tol)
This function checks that all the simulation outputs follow the conventions of the simulator.
The conventions that are checked by this function include:
The terrain should not overlap with the body.
The body should be properly defined, with its maximum height higher than its minimum height.
The body soil should be properly defined, with its maximum height higher than its minimum height.
The two body layers should not overlap or touch each other.
One body layer should not overlap with all body soil layer.
The body should not overlap with the corresponding body soil layer.
The body soil layer should be resting on the corresponding body layer.
The body should be present when there is body soil.
- Parameters:
sim_out – Class that stores simulation outputs.
tol – Small number used to handle numerical approximation errors.
- Returns:
Boolean indicating whether the simulation outputs are consistent.
-
void WriteSoil(SimOut *sim_out, Grid grid)
This function writes the terrain and the body soil into a csv located in the
results
directory.terrain_
andbody_soil_
are saved into files namedterrain
andbody_soil
, respectively, followed by the file number.- Parameters:
sim_out – Class that stores simulation outputs.
grid – Class that stores information related to the simulation grid.
-
void WriteBody(Bucket *bucket)
This function writes the position of all bucket faces into a csv located in the
results
directory.The bucket corners are saved into a file named
bucket
followed by the file number.- Parameters:
bucket – Class that stores information related to the bucket object.
-
void WriteBody(Blade *blade)
This function writes the position of all blade faces into a csv located in the
results
directory.The blade corners are saved into a file named
blade
followed by the file number. Note that only the corners from the front of the blade are written.- Parameters:
blade – Class that stores information related to the blade object.
-
float simplex_noise(float x, float y, std::vector<int> perm_table)
This function creates simplex noise for more realistic terrain generation.
This function implements 2D Simplex noise. A lot of material can be found online concerning this implementation so that the details would not be explicited here.
- Parameters:
x – Rescaled Cartesian coordinate in the X direction.
y – Rescaled Cartesian coordinate in the Y direction.
perm_table – Pre-calculated permutation table to generate pseudo-random noise.
- Returns:
A float representing the Simplex noise.
-
std::tuple<std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>> CalcBodyCornerPos(std::vector<float> pos, std::vector<float> ori, Body *body)