Manual-then-snap controller for a motor + rotation-sensor pair.
More...
#include <rotational_snap.hpp>
|
| | RotationalSnap (pros::AbstractMotor &motor, pros::Rotation &sensor, std::vector< double > snap_angles_deg, double kP=1.5, double tolerance_deg=1.0, int max_snap_speed=80, int input_deadband=5) |
| |
| void | update (int manual_input) |
| | Advance one tick.
|
| |
| void | set_snap_angles (std::vector< double > angles_deg) |
| | Replace the snap angle list at runtime.
|
| |
| void | set_enabled (bool on) |
| | Enable or disable snap behavior.
|
| |
| double | get_position_deg () const |
| |
| double | get_target_deg () const |
| |
| bool | is_snapping () const |
| |
Manual-then-snap controller for a motor + rotation-sensor pair.
Pair any pros::Motor with a pros::Rotation sensor on the same axle. Call update() once per opcontrol tick where manual_input is the blended button + joystick value in the range -127..127.
While |input| > deadband the motor runs manually. The first tick where input transitions back to zero, the controller latches onto the nearest snap angle and runs a P controller to hold it.
Definition at line 33 of file rotational_snap.hpp.
◆ RotationalSnap()
| light::RotationalSnap::RotationalSnap |
( |
pros::AbstractMotor & |
motor, |
|
|
pros::Rotation & |
sensor, |
|
|
std::vector< double > |
snap_angles_deg, |
|
|
double |
kP = 1.5, |
|
|
double |
tolerance_deg = 1.0, |
|
|
int |
max_snap_speed = 80, |
|
|
int |
input_deadband = 5 |
|
) |
| |
- Parameters
-
| motor | motor to drive |
| sensor | rotation sensor on the same axis |
| snap_angles_deg | list of preset angles (degrees) to snap to |
| kP | proportional gain on the snap controller |
| tolerance_deg | considered settled within this many degrees |
| max_snap_speed | speed cap while snapping, 0..127 |
| input_deadband | |input| ≤ this is treated as zero |
◆ get_position_deg()
| double light::RotationalSnap::get_position_deg |
( |
| ) |
const |
- Returns
- Current sensor reading in degrees.
◆ get_target_deg()
| double light::RotationalSnap::get_target_deg |
( |
| ) |
const |
- Returns
- Current snap target in degrees, NaN if none latched.
◆ is_snapping()
| bool light::RotationalSnap::is_snapping |
( |
| ) |
const |
|
inline |
- Returns
- true while the snap controller is actively driving to a target.
Definition at line 99 of file rotational_snap.hpp.
◆ set_enabled()
| void light::RotationalSnap::set_enabled |
( |
bool |
on | ) |
|
Enable or disable snap behavior.
- Parameters
-
| on | true = normal behavior, false = pure passthrough (manual only) |
◆ set_snap_angles()
| void light::RotationalSnap::set_snap_angles |
( |
std::vector< double > |
angles_deg | ) |
|
Replace the snap angle list at runtime.
- Parameters
-
| angles_deg | new list of angles in degrees |
◆ update()
| void light::RotationalSnap::update |
( |
int |
manual_input | ) |
|
Advance one tick.
Call once per opcontrol loop. |input| > deadband → manual control. Going from non-zero to zero latches the nearest snap angle and runs a P-controller to it.
- Parameters
-
| manual_input | operator input, -127..127 |
- Note
- INVARIANT: must be called every tick while the controller is connected. If a tick is missed between non-zero and zero input, the latch may be skipped (the snap target won't engage until the next non-zero → zero transition).
The documentation for this class was generated from the following file: