multirotor.visualize¶
Module Contents¶
Classes¶
A 3D representation of the vehicle. |
Functions¶
|
Plot recorded values from a Multirotor's flight. Including: |
|
Create arrays of x,y,z coordinates for a quiver plot of wind. |
|
Create Atrist objects for vehicle arms, trajectory, body-frame axes. These will |
|
Update the Artist objects for the vehicle arms, trajectory, body-frame axes given |
|
Convenience function for creating a 3D axis. |
|
Check whether code is running in a text console or jupyter notebook. |
- multirotor.visualize.plot_datalog(log: multirotor.helpers.DataLog, figsize=(21, 10.5), plots=('pos', 'vel', 'ctrl', 'traj'), nrows=2, ncols=None) Dict[str, matplotlib.pyplot.Axes]¶
Plot recorded values from a Multirotor’s flight. Including:
Position and orientation,
Motor speeds,
Velocity in world frame,
Control allocation,
Allocation errors,
2D x-y position plot
Parameters¶
- logDataLog
The datalog, where datalog.done_logging() has been called.
- figsizetuple, optional
The x/y dimensions of the figure, by default (21,10.5)
Returns¶
- DictDict[str, plt.Axes]
A dictionary of plot names mapping to Axes
- multirotor.visualize.get_wind_quiver(heading: str, ax: matplotlib.pyplot.Axes, n=5, dim=2)¶
Create arrays of x,y,z coordinates for a quiver plot of wind.
Parameters¶
- headingstr
The heading of the wind, e.g. ‘5@45’ for 5N wind from 45 degrees.
- axplt.Axes
The axes on which to plot the quiver.
- nint, optional
Size of arrays, by default 5
- dimint, optional
Dimension of quiver (2 or 3), by default 2
Returns¶
- Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]
x,y,[z],dx,dy,[dz] coordinates for quiver plot.
- class multirotor.visualize.VehicleDrawing(vehicle: multirotor.simulation.Multirotor, axis: mpl_toolkits.mplot3d.Axes3D = None, trace: bool = False, body_axes: bool = False, make_fig_kwargs: dict = dict(xlim=(-10, 10), ylim=(-10, 10), zlim=(-10, 10)))¶
A 3D representation of the vehicle.
- update() float¶
Draw vehicle position and orientation on the figure.
Returns¶
- float
The time (seconds) taken to finish this operation.
- reset()¶
Clear vehicle’s trajectory, and place vehicle at its current position.
- multirotor.visualize.make_drawing(params: multirotor.vehicle.VehicleParams, body_axes: bool = False, make_2d: bool = False, scale_arms=1.0) Tuple[List[matplotlib.lines.Line2D | mpl_toolkits.mplot3d.art3d.Line3D], numpy.ndarray, matplotlib.lines.Line2D | mpl_toolkits.mplot3d.art3d.Line3D, List[matplotlib.lines.Line2D | mpl_toolkits.mplot3d.art3d.Line3D], numpy.ndarray]¶
Create Atrist objects for vehicle arms, trajectory, body-frame axes. These will then be added to the Figure.
Parameters¶
- paramsVehicleParams
The description of the vehicle.
- body_axesbool, optional
Whether to draw body-frame x/y/z axes, by default False
- make_2dbool, optional
Whether to return 2D lines (if using these for some 2D plot), by default False
- scale_arms_type_, optional
Factor by which to scale arm lengths. Useful when a small vehicle must be made visible in a plot with large bounds, by default 1.
Returns¶
- Tuple
List of lines for vehicle propeller arms,
Array of (2*propellers) x [2|3] containing end-points of arm lines in [2|3] dimensions
The line object of the vehicle trajectory
List of lines for body-frame axes
Array of (2*3) x 3 containing end-points of body-frame axis lines in [2|3] dimensions.
- multirotor.visualize.update_drawing(drawing: VehicleDrawing, position: numpy.ndarray, orientation: numpy.ndarray) Tuple[List[matplotlib.lines.Line2D | mpl_toolkits.mplot3d.art3d.Line3D], matplotlib.lines.Line2D | mpl_toolkits.mplot3d.art3d.Line3D, List[matplotlib.lines.Line2D | mpl_toolkits.mplot3d.art3d.Line3D]]¶
Update the Artist objects for the vehicle arms, trajectory, body-frame axes given position and orientation.
Parameters¶
- drawingVehicleDrawing
The drawing to update.
- positionnp.ndarray
The 3D position of the vehicle,
- orientationnp.ndarray
The orientation (radians) of the vehicle
Returns¶
- Tuple
List of lines for vehicle propeller arms,
The line object of the vehicle trajectory
List of lines for body-frame axes
- multirotor.visualize.make_fig(xlim: Tuple[float, float], ylim: Tuple[float, float], zlim: Tuple[float, float], **fig_kwargs) Tuple[matplotlib.pyplot.Figure, mpl_toolkits.mplot3d.Axes3D]¶
Convenience function for creating a 3D axis.
Parameters¶
- xlim/ylim/zlimTuple[float, float]
Min/max coordinates in plot
Returns¶
- Tuple[plt.Figure, Axes3D]
The figure and Axes3D instance