Exported Functions
Reading config files
KiteUtils.set_data_path
— Functionset_data_path(data_path="")
Set the directory for log and config files.
If called without argument, use the data path of the package to obtain the default settings when calling se().
KiteUtils.load_settings
— Functionload_settings(project=PROJECT)
Load the project with the given file name.
The project must include the path and the suffix .yaml .
KiteUtils.update_settings
— Functionupdate_settings()
Re-read the settings from a previously loaded project. Returns the new settings.
KiteUtils.copy_settings
— Functioncopy_settings()
Copy the default settings.yaml and system.yaml files to the folder DATAPATH (it will be created if it doesn't exist).
KiteUtils.se
— Functionse(project=PROJECT)
Getter function for the Settings
struct.
The settings.yaml file to load is determined by the content active PROJECT, which defaults to system.yaml
. The project file must be located in the directory specified by the variable DATA_PATH
.
KiteUtils.se_dict
— Functionse_dict()
Getter function for the dictionary, representing the settings.yaml file.
Access to the dict is much slower than access to the setting struct, but more flexible.
Usage example: z0 = se_dict()["environment"]["z0"]
Also look at the default example: settings.yaml .
Modify .yaml files
KiteUtils.readfile
— Functionreadfile(filename)
Read the lines of a text file.
KiteUtils.writefile
— Functionwritefile(lines, filename)
Write the lines to a file.
KiteUtils.change_value
— Functionchange_value(lines, varname, value::Union{Integer, Float64})
Change the value of a variable in a yaml file for a number.
change_value(lines, varname, value::String)
Change the value of a variable in a yaml file.
KiteUtils.get_comment
— Functionget_comment(lines, key)
Get the comment of a variable in a yaml file.
KiteUtils.get_unit
— Functionget_unit(lines, key)
Get the unit of a variable in a yaml file. The unit must be defined in square brackets.
Creating test data
KiteUtils.demo_state
— Functiondemo_state(P, height=6.0, time=0.0; azimuth_north=-pi/2)
Create a demo state with a given height and time. P is the number of tether particles. Kite is parking and aligned with the tether.
Returns a SysState instance.
KiteUtils.demo_state_4p
— Functiondemo_state_4p(P, height=6.0, time=0.0; azimuth_north=-pi/2)
Create a demo state, using the 4 point kite model with a given height and time. P is the number of tether particles.
Returns a SysState instance.
KiteUtils.demo_state_4p_3lines
— Functiondemo_state_4p_3lines(P, height=6.0, time=0.0)
Create a demo state, using the 4 point kite model with a given height and time. P is the number of middle tether particles.
Returns a SysState instance.
KiteUtils.demo_syslog
— Functiondemo_syslog(P, name="Test flight"; duration=10)
Create a demo flight log with given name [String] and duration [s] as StructArray. P is the number of tether particles.
KiteUtils.demo_log
— Functiondemo_log(P, name="Test_flight"; duration=10)
Create an artifical SysLog struct for demonstration purposes. P is the number of tether particles.
KiteUtils.get_particles
— Functionget_particles(height_k, height_b, width, m_k, pos_pod= [ 75., 0., 129.90381057], vec_c=[-15., 0., -25.98076211],
v_app=[10.4855, 0, -3.08324])
Calculate the initial positions of the particels representing a 4-point kite, connected to a kite control unit (KCU).
Parameters:
- height_k: height of the kite itself, not above ground [m]
- height_b: height of the bridle [m]
- width: width of the kite [m]
- mk: relative nose distance
- pos_pod: position of the control pod
- vec_c: vector of the last tether segment
KiteUtils.get_particles_3l
— FunctionCalculate the initial positions of the particles representing a 4-point 3 line kite.
Loading, saving and converting log files
KiteUtils.log!
— Functionlog!(logger::Logger, state::SysState)
Log a state in a logger object. Do nothing if the preallocated size would be exceeded. Returns the current number of elements of the log.
KiteUtils.load_log
— Functionload_log(filename::String; path="")
Read a log file that was saved as .arrow file.
KiteUtils.save_log
— Functionsave_log(logger::Logger, name="sim_log", compress=true;
path="",
colmeta = Dict(:var_01 => ["name" => "var_01"],
:var_02 => ["name" => "var_02"],
:var_03 => ["name" => "var_03"],
:var_04 => ["name" => "var_04"],
:var_05 => ["name" => "var_05"],
:var_06 => ["name" => "var_06"],
:var_07 => ["name" => "var_07"],
:var_08 => ["name" => "var_08"],
:var_09 => ["name" => "var_09"],
:var_10 => ["name" => "var_10"],
:var_11 => ["name" => "var_11"],
:var_12 => ["name" => "var_12"],
:var_13 => ["name" => "var_13"],
:var_14 => ["name" => "var_14"],
:var_15 => ["name" => "var_15"],
:var_16 => ["name" => "var_16"]
))
Save a fligh log from a logger as .arrow file. By default lz4 compression is used, if you use false as second parameter no compression is used.
save_log(flight_log::SysLog, compress=true; path="")
Save a fligh log of type SysLog as .arrow file. By default lz4 compression is used, if you use false as second parameter no compression is used.
KiteUtils.import_log
— Functionimport_log(filename)
Read a .csv file with a flight log and return a SysLog object. The columns var_01
to var_05
must exists, the rest are optional.
Parameters:
- filename: name of the file without extension.
KiteUtils.export_log
— Functionexport_log(flight_log; path="")
Save a fligh log of type SysLog as .csv file.
KiteUtils.sys_log
— Functionsys_log(logger::Logger, name="sim_log";
colmeta = Dict(:var_01 => ["name" => "var_01"],
:var_02 => ["name" => "var_02"],
:var_03 => ["name" => "var_03"],
:var_04 => ["name" => "var_04"],
:var_05 => ["name" => "var_05"],
:var_06 => ["name" => "var_06"],
:var_07 => ["name" => "var_07"],
:var_08 => ["name" => "var_08"],
:var_09 => ["name" => "var_09"],
:var_10 => ["name" => "var_10"],
:var_11 => ["name" => "var_11"],
:var_12 => ["name" => "var_12"],
:var_13 => ["name" => "var_13"],
:var_14 => ["name" => "var_14"],
:var_15 => ["name" => "var_15"],
:var_16 => ["name" => "var_16"]
))
Converts the data of a Logger object into a SysLog object, containing a StructArray, a name and the column meta data.
Base.getproperty
— FunctionBase.getproperty(log::SysLog, sym::Symbol)
Implement the properties x, y and z. They represent the kite position for the 4-point kite model. In addition, implements the properties x1, y1 and z1. They represent the kite position for the 1-point model.
The function set_data_path(data_path)
can be used to set the directory for the log files.
Rotation matrices and conversions
KiteUtils.calc_orient_rot
— Functioncalc_orient_rot(x, y, z; viewer=false, ENU=true)
Calculate the rotation matrix based on the kite reference frame, by default passed as ENU (east, north, up), or as NED (north, east, down) if ENU is false. If viewer is true, the rotation matrix is calculated based with respect to the viewer reference frame.
KiteUtils.enu2ned
— Functionenu2ned(vec::AbstractVector)
Convert a vector from ENU (east, north, up) to NED (north, east, down) reference frame.
KiteUtils.ned2enu
— Functionned2enu(vec::AbstractVector)
Convert a vector from NED (north, east, down) to ENU (east, north, up) reference frame.
KiteUtils.is_right_handed_orthonormal
— Functionis_right_handed_orthonormal(x, y, z)
Returns true
if the vectors x
, y
and z
form a right-handed orthonormal basis.
KiteUtils.quat2euler
— Functionquat2euler(q::QuatRotation)
quat2euler(q::AbstractVector)
Convert a quaternion to roll, pitch, and yaw angles in radian. The quaternion can be a 4-element vector (w, i, j, k) or a QuatRotation object.
KiteUtils.quat2viewer
— Functionquat2viewer(q::QuatRotation)
quat2viewer(rot::AbstractMatrix)
quat2viewer(orient::AbstractVector)
Convert the quaternion q to the viewer reference frame. It can also be passed as a rotation matrix or as 4-element vector [w,i,j,k], where w is the real part and i, j, k are the imaginary parts of the quaternion.
KiteUtils.euler2rot
— Functioneuler2rot(roll, pitch, yaw)
Calculate the rotation matrix based on the roll, pitch, and yaw angles in radian.
KiteUtils.rot3d
— Methodrot3d(ax, ay, az, bx, by, bz)
Calculate the rotation matrix that needs to be applied on the reference frame (ax, ay, az) to match the reference frame (bx, by, bz). All parameters must be 3-element vectors. Both refrence frames must be orthogonal, all vectors must already be normalized.
Source: TRIAD_Algorithm
KiteUtils.rot
— Methodrot(pos_kite, pos_before, v_app)
Calculate the rotation matrix of the kite based on the position of the last two tether particles and the apparent wind speed vector. Assumption: The kite aligns with the apparent wind direction. If used for the model KPS4
, pass the vector -x
of the kite reference frame instead of v_app.
Coordinate system transformations
KiteUtils.fromENU2EG
— FunctionfromENU2EG(pointENU)
Transform the position of the kite in the East North Up reference frame to the Earth Groundstation (North West Up) reference frame.
KiteUtils.fromEG2W
— FunctionfromEG2W(vector, down_wind_direction = pi/2.0)
Transform a vector (x,y,z) from Earth Groundstation to Wind reference frame.
KiteUtils.fromW2SE
— FunctionfromW2SE(vector, elevation, azimuth)
Transform a (velocity-) vector (x,y,z) from Wind to Small Earth reference frame .
KiteUtils.fromKS2EX
— FunctionfromKS2EX(vector, orientation)
Transform a vector (x,y,z) from KiteSensor to Earth Xsens reference frame.
- orientation in Euler angles (roll, pitch, yaw)
KiteUtils.fromEX2EG
— FunctionfromEX2EG(vector)
Transform a vector (x,y,z) from EarthXsens to Earth Groundstation reference frame
Geometric calculations
Calculate the elevation angle, the azimuth angle and the ground distance based on the kite position. In addition, calculate the heading angle, the heading vector, the asin and acos (safe versions) and the initial kite reference frame.
KiteUtils.calc_elevation
— Functioncalc_elevation(vec)
Calculate the elevation angle in radian from the kite position.
KiteUtils.calc_heading
— Functioncalc_heading(orientation, elevation, azimuth; upwind_dir=-pi/2, respos=true)
Calculate the heading angle of the kite in radians. The heading is the direction the nose of the kite is pointing to. The orientation is given in Euler angles, calculated with respect to the North, East, Down reference frame. If respos is true the heading angle is defined in the range of 0 .. 2π, otherwise in the range -π .. π
KiteUtils.calc_course
— Functioncalc_course(velocityENU, elevation, azimuth, down_wind_direction = π/2, respos=true)
Calculate the course angle in radian.
- velocityENU: Kite velocity in EastNorthUp reference frame
- downwinddirection: The direction the wind is going to; zero at north; clockwise positive from above; default: going to east.
- respos: If true, the result is in the range 0 .. 2π, otherwis -π .. π
KiteUtils.calc_heading_w
— Functioncalc_heading_w(orientation, down_wind_direction = pi/2.0)
Calculate the heading vector in wind reference frame.
KiteUtils.azimuth_east
— Functionazimuth_east(vec)
Calculate the azimuth angle in radian from the kite position in ENU reference frame. Zero east. Positive direction clockwise seen from above. Valid range: -π .. π.
KiteUtils.azimuth_north
— Functionazimuth_north(vec)
Calculate the azimuth angle in radian from the kite position in ENU reference frame. Zero north. Positive direction anti-clockwise seen from above. Valid range: -π .. π.
KiteUtils.azn2azw
— Functionazn2azw(azimuth_north; upwind_dir = -π/2)
Calculate the azimuth in the wind reference frame. The upwind_dir
is the direction the wind is coming from Zero is at north; clockwise positive. Default: Wind from west.
Returns:
- Angle in radians. Zero straight downwind. Positive direction clockwise seen from above.
- Valid range: -pi .. pi.
KiteUtils.ground_dist
— Functionground_dist(vec)
Calculate the ground distance of the kite from the groundstation based on the kite position (x,y,z, z up).
KiteUtils.acos2
— Functionacos2(arg)
Calculate the acos of arg, but allow values slightly above one and below minus one to avoid exceptions in case of rounding errors. Returns an angle in radian.
KiteUtils.asin2
— Functionasin2(arg)
Calculate the asin of arg, but allow values slightly above one and below minus one to avoid exceptions in case of rounding errors. Returns an angle in radian.
KiteUtils.wrap2pi
— Functionwrap2pi(angle)
Limit the angle to the range -π .. π .
KiteUtils.initial_kite_ref_frame
— Functioninitial_kite_ref_frame(vec_c, v_app)
Calculate the initial orientation of the kite based on the last tether segment and the apparent wind speed.
Parameters:
vec_c
: (pos_n
-2) - (pos_n
-1) n: number of particles without the three kite particles that do not belong to the main thether (P1, P2 and P3).v_app
: vector of the apparent wind speed
Returns: x, y, z: the unit vectors of the kite reference frame in the ENU reference frame
Physical calculations
KiteUtils.calculate_rotational_inertia
— Functioncalculate_rotational_inertia(X::Vector, Y::Vector, Z::Vector, M::Vector,
around_center_of_mass::Bool=true, rotation_point::Vector=[0, 0, 0])
Calculate the rotational inertia (Ixx, Ixy, Ixz, Iyy, Iyz, Izz) of a collection of point masses around a point. By default this point is the center of mass which will be calculated, but any point can be given to rotation_point.
Parameters:
- X: x-coordinates of the point masses.
- Y: y-coordinates of the point masses.
- Z: z-coordinates of the point masses.
- M: masses of the point masses.
around_center_of_mass
: Calculate the rotational inertia around the center of mass?rotation_point
: Rotation point used if not rotating around the center of mass.
Returns: The tuple Ixx, Ixy, Ixz, Iyy, Iyz, Izz where:
- Ixx: rotational inertia around the x-axis.
- Ixy: rotational inertia around the xy-plane.
- Ixz: rotational inertia around the xz-plane.
- Iyy: rotational inertia around the y-axis.
- Iyz: rotational inertia around the yz-plane.
- Izz: rotational inertia around the z-axis.