Data Structures | Functions
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

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:
motionMotionController to initialise
motorMotorGroup to drive
encoder_portEncoder port to read motor position from
kpProportional constant for PID
kiIntegral constant for PID
kdDerivative 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:
motionMotionController to set
goalGoal position to drive towards
void motion_update ( MotionController motion)

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

Parameters:
motionMotionController to run