lib/motion.h File Reference

A PID-controlled MotorGroup. More...

#include <kern/global.h>
#include <lib/motor_group.h>
#include <lib/pid.h>


Data Structures

struct  MotionController

Functions

void motion_init (MotionController *motion, MotorGroup motor, uint8_t encoder_port, float kp, float ki, float kd)
void motion_set_goal (MotionController *motion, int32_t goal)
void motion_update (MotionController *motion)
bool motion_goal_reached (MotionController *motion)

Detailed Description

A MotionController provides a PID-controlled MotorGroup.

Given a MotorGroup (one or more motors), an encoder port and a target position, the MotionController will attempt to drive the MotorGroup to the given target.


Function Documentation

bool motion_goal_reached ( MotionController motion  ) 

Check if the MotionController's goal has been reached

Returns:
true if goal reached, false otherwise

void motion_init ( MotionController motion,
MotorGroup  motor,
uint8_t  encoder_port,
float  kp,
float  ki,
float  kd 
)

Create a new MotionController

Parameters:
motion MotionController to initialise
motor MotorGroup to drive
encoder_port Encoder port to read motor position from
kp Proportional constant for PID
ki Integral constant for PID
kd Derivative constant for PID

void motion_set_goal ( MotionController motion,
int32_t  goal 
)

Set the target position for the MotionController. The controller will immediately start driving the motor towards the goal.

Parameters:
motion MotionController to set
goal Goal position to drive towards

void motion_update ( MotionController motion  ) 

Perform one cycle of the motion controller loop. Call as often as possible.

Parameters:
motion MotionController to run