Turning
Functions with Okapi Units​
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(24_deg, 110);
chassis.pid_wait();
}
void pid_turn_set(okapi::QAngle p_target, int speed);
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(22.5_deg, 110, ez::longest);
chassis.pid_wait();
}
void pid_turn_set(okapi::QAngle p_target, int speed, e_angle_behavior behavior);
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(24_deg, 110, true);
chassis.pid_wait();
}
void pid_turn_set(okapi::QAngle p_target, int speed, bool slew_on);
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(22.5_deg, 110, ez::longest, true);
chassis.pid_wait();
}
void pid_turn_set(okapi::QAngle p_target, int speed, e_angle_behavior behavior, bool slew_on);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90_deg, 110);
chassis.pid_wait();
// Turns backwards by 45 degrees
chassis.pid_turn_relative_set(-45_deg, 110);
chassis.pid_wait();
}
void pid_turn_relative_set(okapi::QAngle p_target, int speed);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90_deg, 110, true);
chassis.pid_wait();
// Turns backwards by 45 degrees
chassis.pid_turn_relative_set(-45_deg, 110, true);
chassis.pid_wait();
}
void pid_turn_relative_set(okapi::QAngle p_target, int speed, bool slew_on);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90_deg, 110, ez::shortest);
chassis.pid_wait();
// Turns the long way around to go -45 from where it started
chassis.pid_turn_relative_set(-45_deg, 110, ez::longest);
chassis.pid_wait();
}
void pid_turn_relative_set(okapi::QAngle p_target, int speed, e_angle_behavior behavior);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
p_target
target value in okapi angle units
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90_deg, 110, ez::shortest, true);
chassis.pid_wait();
// Turns the long way around to go -45 from where it started
chassis.pid_turn_relative_set(-45_deg, 110, ez::longest, true);
chassis.pid_wait();
}
void pid_turn_relative_set(okapi::QAngle p_target, int speed, e_angle_behavior behavior, bool slew_on);
pid_turn_exit_condition_set()​
Set's constants for turn exit conditions.
p_small_exit_time
time to exit when within small_error, okapi unit
p_small_error
small timer will start when error is within this, okapi unit
p_big_exit_time
time to exit when within big_error, okapi unit
p_big_error
big timer will start when error is within this, okapi unit
p_velocity_exit_time
velocity timer will start when velocity is 0, okapi unit
p_mA_timeout
mA timer will start when the motors are pulling too much current, okapi unit
use_imu
true adds the imu for velocity calculation in conjunction with the main sensor, false doesn't
- Prototype
- Example
void initialize() {
chassis.pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
}
void pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, use_imu = true);
pid_turn_chain_constant_set()​
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion.
This sets turning constants.
input
okapi angle unit
- Prototype
- Example
void initialize() {
chassis.pid_turn_chain_constant_set(3_deg);
}
void pid_turn_chain_constant_set(okapi::QAngle input);
slew_turn_constants_set()​
Sets constants for slew for turns.
Slew ramps up the speed of the robot until the set distance is traveled.
distance
the distance the robot travels before reaching max speed, an okapi angle unit
min_speed
the starting speed for the movement, 0 - 127
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.slew_turn_constants_set(5_deg, 50);
chassis.pid_turn_set(-90_deg, 110, true);
chassis.pid_wait();
}
void slew_turn_constants_set(okapi::QAngle distance, int min_speed);
Functions without Okapi Units​
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
target
target value in degrees
speed
0 to 127, max speed during motion
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(24, 110);
chassis.pid_wait();
}
void pid_turn_set(double target, int speed);
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
target
target value in degrees
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(22.5, 110, ez::longest);
chassis.pid_wait();
}
void pid_turn_set(double target, int speed, e_angle_behavior behavior);
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
target
target value in degrees
speed
0 to 127, max speed during motion
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(24, 110, true);
chassis.pid_wait();
}
void pid_turn_set(double target, int speed, bool slew_on);
pid_turn_set()​
Sets the robot to turn using PID relative to initial heading.
target
target value in degrees
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(22.5, 110, ez::longest, true);
chassis.pid_wait();
}
void pid_turn_set(double target, int speed, e_angle_behavior behavior, bool slew_on);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
target
target value in degrees
speed
0 to 127, max speed during motion
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90, 110);
chassis.pid_wait();
// Turns backwards by 45 degrees
chassis.pid_turn_relative_set(-45, 110);
chassis.pid_wait();
}
void pid_turn_relative_set(double target, int speed);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
target
target value in degrees
speed
0 to 127, max speed during motion
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90, 110, true);
chassis.pid_wait();
// Turns backwards by 45 degrees
chassis.pid_turn_relative_set(-45, 110, true);
chassis.pid_wait();
}
void pid_turn_relative_set(double target, int speed, bool slew_on);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
target
target value in degrees
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90, 110, ez::shortest);
chassis.pid_wait();
// Turns the long way around to go -45 from where it started
chassis.pid_turn_relative_set(-45, 110, ez::longest);
chassis.pid_wait();
}
void pid_turn_relative_set(double target, int speed, e_angle_behavior behavior);
pid_turn_relative_set()​
Sets the robot to turn using PID relative to the current heading.
target
target value in degrees
speed
0 to 127, max speed during motion
behavior
changes what direction the robot will turn. can be left, right, shortest, longest, raw
slew_on
ramp up from a lower speed to your target speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Turns to 90 deg
chassis.pid_turn_relative_set(90, 110, ez::shortest, true);
chassis.pid_wait();
// Turns the long way around to go -45 from where it started
chassis.pid_turn_relative_set(-45, 110, ez::longest, true);
chassis.pid_wait();
}
void pid_turn_relative_set(double target, int speed, e_angle_behavior behavior, bool slew_on);
pid_turn_exit_condition_set()​
Set's constants for turn exit conditions.
p_small_exit_time
time to exit when within small_error, in ms
p_small_error
small timer will start when error is within this, in degrees
p_big_exit_time
time to exit when within big_error, in ms
p_big_error
big timer will start when error is within this, in degrees
p_velocity_exit_time
velocity timer will start when velocity is 0, in ms
p_mA_timeout
mA timer will start when the motors are pulling too much current, in ms
use_imu
true adds the imu for velocity calculation in conjunction with the main sensor, false doesn't
- Prototype
- Example
void initialize() {
chassis.pid_turn_exit_condition_set(300, 1, 500, 3, 750, 750);
}
void pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, use_imu = true);
pid_turn_constants_set()​
Set PID drive constants for turns.
p
proportional term
i
integral term
d
derivative term
p_start_i
error threshold to start integral
- Prototype
- Example
void initialize() {
chassis.pid_turn_constants_set(3, 0, 20);
}
void pid_turn_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_turn_chain_constant_set()​
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion.
This sets turning constants.
input
angle in degrees
- Prototype
- Example
void initialize() {
chassis.pid_turn_chain_constant_set(3);
}
void pid_turn_chain_constant_set(double input);
slew_turn_set()​
Sets the default slew for turn motions, can be overwritten in movement functions.
slew_on
true enables, false disables
- Prototype
- Example
void slew_turn_set(bool slew_on);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Set the default slew state to true
chassis.slew_turn_set(true);
// This will not use slew because we explicitly told the robot to not slew
chassis.pid_turn_set(90_deg, 90, false);
chassis.pid_wait();
// This will slew because it's the default state
chassis.pid_drive_set(0_deg, 90);
chassis.pid_wait();
}
pid_turn_min_set()​
The minimum power for turns when kI and startI are enabled.
min
new clipped speed
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_min_set(30);
chassis.pid_turn_set(45, 110);
chassis.pid_wait();
}
void pid_turn_min_set(int min);
pid_turn_behavior_set()​
Sets the default behavior for turns in turning movements.
behavior
ez::shortest, ez::longest, ez::left, ez::right, ez::raw
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_behavior_set(ez::longest); // Set the robot to take the longest path there
// This will make the robot go the long way around to get to 90 degrees
chassis.pid_turn_set(90_deg, 110);
chassis.pid_wait();
}
void pid_turn_behavior_set(e_angle_behavior behavior);
Getter​
pid_turn_chain_constant_get()​
Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for turning.
- Prototype
- Example
void initialize() {
chassis.pid_turn_chain_constant_set(3_deg);
printf("%.2f\n", chassis.pid_turn_chain_constant_get());
}
double pid_turn_chain_constant_get();
slew_turn_get()​
Returns true if slew is enabled for all turn motions, false otherwise.
- Prototype
- Example
bool slew_turn_get();
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
// Set the default slew state to true
chassis.slew_turn_set(true);
if (chassis.slew_turn_get())
printf("Turn Slew is Enabled!\n");
// This will not use slew because we explicitly told the robot to not slew
chassis.pid_turn_set(90_deg, 90, false);
chassis.pid_wait();
// This will slew because it's the default state
chassis.pid_drive_set(0_deg, 90);
chassis.pid_wait();
}
pid_turn_min_get()​
Returns minimum power for turns when kI and startI are enabled.
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_min_set(30);
printf("Turn Min: %i", chassis.pid_turn_min_get());
}
int pid_turn_min_get();
pid_turn_behavior_get()​
Returns the turn behavior for turns.
- Prototype
- Example
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_behavior_set(ez::longest); // Set the robot to take the longest path there
if (chassis.pid_turn_behavior_get() == ez::longest) {
printf("Current behavior is ez::longest!\n");
} else {
printf("Current behavior is not ez::longest!\n");
}
// This will make the robot go the long way around to get to 90 degrees
chassis.pid_turn_set(90_deg, 110);
chassis.pid_wait();
}
e_angle_behavior pid_turn_behavior_get();