Trajectory Builder
Build trajectories from a definition (either from a yaml file or directly via python dictionary).
- class sorotraj.build_traj.TrajBuilder(verbose=False, **kwargs)
Trajectory builder
- verbose
Flag used to turn on verbose printing
- Type
bool
Examples
>>> def_file = 'examples/traj_setup/setpoint_traj_demo.yaml' ... builder = TrajBuilder() ... builder.load_traj_def(def_file) ... traj = builder.get_trajectory() ... out_file = 'examples/traj_built/setpoint_traj_demo.traj' ... builder.save_traj(out_file)
- build_traj()
Build the current trajectory
- Raises
RuntimeError – If the trajectory definition has not been set
- convert_definition(conversion_fun)
Convert a trajectory definition line-by-line using a conversion function.
Trajectory definition of type ‘direct’ and ‘interp’ can be converted, but waveform trajectory definitions cannot.
- Parameters
conversion_fun (function) – Conversion function taking in one waypoint (list) and returning waypoint (list)
- Raises
RuntimeError – If the trajectory definition is not set
RuntimeError – If the trajectory type is incompatible (not direct or interp)
- convert_traj(conversion_fun)
Convert a trajectory line-by-line using a conversion function
- Parameters
conversion_fun (function) – Conversion function taking in one trajectory line (list) and returning one line (list)
- Raises
RuntimeError – If the trajectory has not been built
- get_definition(use_copy=False)
Get the trajectory definition.
- Parameters
use_copy (bool) – Decide whether to pass the trajectory by referece. If True, the actual trajectory object is returned, otherwise a copy of the trajectory is returned.
- Returns
trajectory_definition – The trajectory definition
- Return type
dict
- Raises
RuntimeError – If the trajectory definition is not set set
- get_traj_components()
Get trajectory split into compoenents rather than in vector form
This generates a dictionary with the same trajectory components as a usual trajectory, but the values of each component are dictionaries with ‘time’ and ‘values’ rather than the usual list of lists.
- Raises
RuntimeError – If the trajectory has not been built
- get_trajectory(use_copy=False)
Get the built trajectory.
- Parameters
use_copy (bool) – Decide whether to pass the trajectory by referece. If True, the actual trajectory object is returned, otherwise a copy of the trajectory is returned.
- Returns
trajectory – The full trajectory
- Return type
dict
- Raises
RuntimeError – If the trajectory has not been built
- load_traj_def(filename)
Load a trajectory definition from a file.
Once lodaed, the trajectory definition is set, and the trajectory is built.
- Parameters
filename (str) – The file to load
- Raises
ValueError – If the filename is not of type ‘str’
- plot_traj(fig_kwargs={}, plot_kwargs={})
Plot the current trajectory (assuming 1 rep of the main segment)
- Parameters
fig_kwargs (Any) – Keyword args to pass to the matplotlib’s figure function
plot_kwargs (Any) – Keyword args to pass to the matplotlib’s plotting function
- Raises
RuntimeError – If the trajectory has not been built
- save_definition(filename)
Save the trajectory definition to a file.
- Parameters
filename (str) – The file to save
- Raises
ValueError – If the filename is not of type ‘str’
RuntimeError – If the trajectory definition is not set
- save_traj(filename)
Save the trajectory to a file.
- Parameters
filename (str) – The file to save
- Raises
ValueError – If the filename is not of type ‘str’
RuntimeError – If the trajectory has not been built
- set_definition(definition)
Set the trajectory definition manually.
The trajectory definition is set, and the trajectory is rebuilt.
- Parameters
definition (dict) – The trajectory definition to set
- Raises
ValueError – If the trajectory definition is not of type ‘dict’