Pathfinder API¶

pathfinder.
generate
()¶ pathfinder_generate(path: List[pathfinder._pathfinder.Waypoint], fit: capsule, sample_count: int, dt: float, max_velocity: float, max_acceleration: float, max_jerk: float) > Tuple[pathfinder._pathfinder.TrajectoryInfo, List[pathfinder._pathfinder.Segment]]
Generate a motion profile trajectory using the given waypoints and configuration.
Parameters:  path – A list of waypoints (setpoints) for the trajectory path to intersect
 fit – A fit function; use FIT_HERMITE_CUBIC or FIT_HERMITE_QUINTIC
 sample_count –
 dt –
 max_velocity –
 max_acceleration –
 max_jerk –
Returns: A tuple of TrajectoryInfo, and a generated trajectory (a list of segments)

pathfinder.
d2r
()¶ radians(x)
Convert angle x from degrees to radians.

pathfinder.
r2d
()¶ degrees(x)
Convert angle x from radians to degrees.
Followers¶

class
pathfinder.followers.
DistanceFollower
(trajectory)[source]¶ The DistanceFollower is an object designed to follow a trajectory based on distance covered input. This class can be used for Tank or Swerve drive implementations.

calculate
(distance_covered)[source]¶ Calculate the desired output for the motors, based on the distance the robot has covered. This does not account for heading of the robot. To account for heading, add some extra terms in your control loop for realignment based on gyroscope input and the desired heading given by this object.
Parameters: distance_covered ( float
) – The distance covered in metersReturn type: float
Returns: The desired output for your motor controller

configurePIDVA
(kp, ki, kd, kv, ka)[source]¶ Configure the PID/VA Variables for the Follower
Parameters:  kp (
float
) – The proportional term. This is usually quite high (0.8  1.0 are common values)  ki (
float
) – The integral term. Currently unused.  kd (
float
) – The derivative term. Adjust this if you are unhappy with the tracking of the follower. 0.0 is the default  kv (
float
) – The velocity ratio. This should be 1 over your maximum velocity @ 100% throttle. This converts m/s given by the algorithm to a scale of 1..1 to be used by your motor controllers  ka (
float
) – The acceleration term. Adjust this if you want to reach higher or lower speeds faster. 0.0 is the default
Return type: None
 kp (

getHeading
()[source]¶ Return type: float
Returns: the desired heading of the current point in the trajectory


class
pathfinder.followers.
EncoderFollower
(trajectory)[source]¶ The EncoderFollower is an object designed to follow a trajectory based on encoder input. This class can be used for Tank or Swerve drive implementations.

calculate
(encoder_tick)[source]¶ Calculate the desired output for the motors, based on the amount of ticks the encoder has gone through. This does not account for heading of the robot. To account for heading, add some extra terms in your control loop for realignment based on gyroscope input and the desired heading given by this object.
Parameters: encoder_tick ( int
) – The amount of ticks the encoder has currently measured.Return type: float
Returns: The desired output for your motor controller

configureEncoder
(initial_position, ticks_per_revolution, wheel_diameter)[source]¶ Configure the Encoders being used in the follower.
Parameters:  initial_position (
int
) – The initial ‘offset’ of your encoder. This should be set to the encoder value just before you start to track  ticks_per_revolution (
int
) – How many ticks per revolution the encoder has  wheel_diameter (
float
) – The diameter of your wheels (or pulleys for track systems) in meters
Return type: None
 initial_position (

configurePIDVA
(kp, ki, kd, kv, ka)[source]¶ Configure the PID/VA Variables for the Follower
Parameters:  kp (
float
) – The proportional term. This is usually quite high (0.8  1.0 are common values)  ki (
float
) – The integral term. Currently unused.  kd (
float
) – The derivative term. Adjust this if you are unhappy with the tracking of the follower. 0.0 is the default  kv (
float
) – The velocity ratio. This should be 1 over your maximum velocity @ 100% throttle. This converts m/s given by the algorithm to a scale of 1..1 to be used by your motor controllers  ka (
float
) – The acceleration term. Adjust this if you want to reach higher or lower speeds faster. 0.0 is the default
Return type: None
 kp (

getHeading
()[source]¶ Return type: float
Returns: the desired heading of the current point in the trajectory

Modifiers¶

class
pathfinder.modifiers.
SwerveModifier
(source)[source]¶ The Swerve Modifier will take in a Source Trajectory and spit out 4 trajectories, 1 for each wheel on the drive. This is commonly used in robotics for robots with 4 individual wheels in a ‘swerve’ configuration, where each wheel can rotate to a specified heading while still being powered.
The Source Trajectory is measured from the centre of the drive base. The modification will not modify the central trajectory

getBackLeftTrajectory
()[source]¶ Get the trajectory for the backleft wheel of the drive base
Return type: List
[Segment
]

getBackRightTrajectory
()[source]¶ Get the trajectory for the backright wheel of the drive base
Return type: List
[Segment
]

getFrontLeftTrajectory
()[source]¶ Get the trajectory for the frontleft wheel of the drive base
Return type: List
[Segment
]

getFrontRightTrajectory
()[source]¶ Get the trajectory for the frontright wheel of the drive base
Return type: List
[Segment
]

modify
(wheelbase_width, wheelbase_depth)[source]¶ Generate the Trajectory Modification
Parameters:  wheelbase_width (
float
) – The width (in meters) between the individual leftright sides of the drivebase  wheelbase_depth (
float
) – The width (in meters) between the individual frontback sides of the drivebase
Return type: Returns: self
 wheelbase_width (


class
pathfinder.modifiers.
TankModifier
(source)[source]¶ The Tank Modifier will take in a Source Trajectory and a Wheelbase Width and spit out a Trajectory for each side of the wheelbase. This is commonly used in robotics for robots which have a drive system similar to a ‘tank’, where individual parallel sides are driven independently
The Source Trajectory is measured from the centre of the drive base. The modification will not modify the central trajectory

getLeftTrajectory
()[source]¶ Get the trajectory for the left side of the drive base
Return type: List
[Segment
]

getRightTrajectory
()[source]¶ Get the trajectory for the right side of the drive base
Return type: List
[Segment
]

modify
(wheelbase_width)[source]¶ Generate the Trajectory Modification
Parameters: wheelbase_width ( float
) – The width (in meters) between the individual sides of the drivebaseReturn type: TankModifier
Returns: self

Serialization¶
For serializing/deserializing in python programs, it’s probably easiest to use
Python’s pickle
module to directly serialize a trajectory:
import pickle
with open('fname', 'wb') as fp:
pickle.dump(trajectory, fp)
with open('fname', 'rb') as fp:
trajectory = pickle.load(fp)
One advantage to this approach is that you could put multiple trajectories in a data structure such as a dictionary, and serialize them all in a single file. The pathfinder compatibility serialization routines only support a single trajectory per file.
However, for compatibility with other pathfinder implementations, the following functions are made available.

pathfinder.
deserialize
()¶ pathfinder_deserialize(fname: str) > List[pathfinder._pathfinder.Segment]
Read a Trajectory from a Binary (non human readable) file

pathfinder.
serialize
()¶ pathfinder_serialize(fname: str, trajectory: List[pathfinder._pathfinder.Segment]) > bool
Write the Trajectory to a Binary (non human readable) file

pathfinder.
serialize_csv
()¶ pathfinder_serialize_csv(fname: str, trajectory: List[pathfinder._pathfinder.Segment]) > bool
Write the Trajectory to a CSV File