joe | 2d92e85 | 2014-01-25 14:31:24 -0800 | [diff] [blame^] | 1 | #include "frc971/control_loops/shooters/shooters.h" |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | #include <algorithm> |
| 6 | |
| 7 | #include "aos/common/control_loop/control_loops.q.h" |
| 8 | #include "aos/common/logging/logging.h" |
| 9 | |
| 10 | #include "frc971/constants.h" |
| 11 | #include "frc971/control_loops/shooters/top_shooter_motor_plant.h" |
| 12 | #include "frc971/control_loops/shooters/bottom_shooter_motor_plant.h" |
| 13 | |
| 14 | namespace frc971 { |
| 15 | namespace control_loops { |
| 16 | |
| 17 | ShooterMotor::ShooterMotor(control_loops::ShooterLoop *my_shooter) |
| 18 | : aos::control_loops::ControlLoop<control_loops::ShooterLoop>(my_shooter), |
| 19 | zeroed_joint_(MakeShooterLoop()) { |
| 20 | { |
| 21 | using ::frc971::constants::GetValues; |
| 22 | ZeroedJoint<1>::ConfigurationData config_data; |
| 23 | |
| 24 | config_data.lower_limit = GetValues().shooter_lower_limit; |
| 25 | config_data.upper_limit = GetValues().shooter_upper_limit; |
| 26 | config_data.hall_effect_start_angle[0] = |
| 27 | GetValues().shooter_hall_effect_start_angle; |
| 28 | config_data.zeroing_off_speed = GetValues().shooter_zeroing_off_speed; |
| 29 | config_data.zeroing_speed = GetValues().shooter_zeroing_speed; |
| 30 | |
| 31 | config_data.max_zeroing_voltage = 5.0; |
| 32 | config_data.deadband_voltage = 0.0; |
| 33 | |
| 34 | zeroed_joint_.set_config_data(config_data); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // Positive angle is up, and positive power is up. |
| 39 | void ShooterMotor::RunIteration( |
| 40 | const ::aos::control_loops::Goal *goal, |
| 41 | const control_loops::ShooterLoop::Position *position, |
| 42 | ::aos::control_loops::Output *output, |
| 43 | ::aos::control_loops::Status * status) { |
| 44 | |
| 45 | // Disable the motors now so that all early returns will return with the |
| 46 | // motors disabled. |
| 47 | if (output) { |
| 48 | output->voltage = 0; |
| 49 | } |
| 50 | |
| 51 | ZeroedJoint<1>::PositionData transformed_position; |
| 52 | ZeroedJoint<1>::PositionData *transformed_position_ptr = |
| 53 | &transformed_position; |
| 54 | if (!position) { |
| 55 | transformed_position_ptr = NULL; |
| 56 | } else { |
| 57 | transformed_position.position = position->pos; |
| 58 | transformed_position.hall_effects[0] = position->hall_effect; |
| 59 | transformed_position.hall_effect_positions[0] = position->calibration; |
| 60 | } |
| 61 | |
| 62 | const double voltage = zeroed_joint_.Update(transformed_position_ptr, |
| 63 | output != NULL, |
| 64 | goal->goal, 0.0); |
| 65 | |
| 66 | if (position) { |
| 67 | LOG(DEBUG, "pos: %f hall: %s absolute: %f\n", |
| 68 | position->pos, |
| 69 | position->hall_effect ? "true" : "false", |
| 70 | zeroed_joint_.absolute_position()); |
| 71 | } |
| 72 | |
| 73 | if (output) { |
| 74 | output->voltage = voltage; |
| 75 | } |
| 76 | status->done = ::std::abs(zeroed_joint_.absolute_position() - goal->goal) < 0.004; |
| 77 | } |
| 78 | |
| 79 | } // namespace control_loops |
| 80 | } // namespace frc971 |