Version: v1.0.1
A Python library that facilitates the control of robot drivetrains with complex motor arrangements.
SimpleDrivetrain provides an easy way to define a drivetrain by the location and orientation of its motors, and calculate the desired velocities for each motor given the overall desired translational velocity and rotational velocities for the drivetrain.
- Local-oriented and field-oriented 3-axis translation and rotation
- Motor-level PWM scaling from user-defined PWM ranges or custom scaling functions
- Support for loading drivetrains from an XML file
- Motion profiles
- Control loop
- Python 2.7+/3.x
- Numpy
- lxml
Install SimpleDrivetrain from PyPI by opening a terminal and typing the following command:
$ pip install simpledrivetrain
from simpledrivetrain.simple_drivetrain import SimpleDrivetraindrivetrain = SimpleDrivetrain()- Motors can be added to the drivetrain by calling the
add_new_motormethod and supplying:- The
nameof the motor, a unique string identifier - The
positionof the motor relative to the drivetrain's center in the form of a 3D coordinate list e.g. [x, y, z] - The motor's positive drive
directionin the form of a 3D cartesian direction vector e.g. [x, y, z] - Optionally, a boolean value
invertedto set whether the motor is inverted - Optionally, a 3-tuple
pwm_boundsin the form of (FULL_REVERSE, FULL STOP, FULL_FORWARD) to which to scale the motor velocity - Optionally, a function
pwm_scaling_funcwhich accepts a motor velocity in [-1, 1] and scales it to a desired pwm range
drivetrain.add_new_motor(name, position, direction, inverted=False, pwm_bounds=(0, 512, 1024), pwm_scaling_func=None)
- The
- Motors can be removed from the drivetrain by calling the
remove_motor_by_namemethod and supplying thenameof the motor to removealternatively, a motor can also be removed from the drivetrain by calling thedrivetrain.remove_motor_by_name(name)
remove_motor_by_indexmethod and supplying the motor'sindexof additiondrivetrain.remove_motor_by_index(index)
- Motors can be accessed by calling the
get_motor_by_namemethod and supplying thenameof the motor to retrievealternatively, a motor can also be accessed by callingmotor = drivetrain.get_motor_by_name(name)
get_motor_by_indexmethod and supplying the motor'sindexof additionmotor = drivetrain.get_motor_by_index(index)
- Motors can also be accessed through the motors instance variable, which stores the
motors by order of addition in a list
motorlist = drivetrain.motors
- Alternatively, motors and orientation can be loaded from an xml file by calling
the
load_drivetrain_from_filemethod and supplying thefilepathstring pointing to the xml file:For an example file, see Example SimpleDrivetrain xml FIle.drivetrain.load_drivetrain_from_file(filepath)
drivetrain.orientation = (pitch, roll, yaw) - Motor velocities scaled in [-1, 1], stored in a list by order of motor
addition, can be calculated by calling the
get_motor_velsmethod and supplying:translation, a 3D vector representing the drivetrain's desired overall velocity, e.g. [x, y, z]rotation, a 3D vector representing the drivetrain's desired rotational velocity, e.g. [pitching, rolling, yawing]force_local_oriented, a boolean value which, if set to true, ignores current drivetrain orientation and calculates local-oriented motor values. It is set to false by default.
drivetrain.get_motor_vels(translation, rotation, force_local_oriented=False)
- Motor velocities scaled according to user-defined, motor-level PWM ranges
or scaling functions, stored in a list by order of motor addition, can be
calculated by calling the
get_motor_vels_scaledmethod and supplying the sametranslation,rotation, andforce_local_orientedparameters as theget_motor_velsmethod:drivetrain.get_motor_vels_scaled(translation, rotation, force_local_oriented=False)
SimpleDrivetrain is distributed under the terms of the MIT License.