blob: b548365dcc3e9f9b36e36fed9a7cc9fe32f5a1b8 [file] [log] [blame]
joe93778a62014-02-15 13:22:14 -08001#include "frc971/control_loops/shooter/shooter.h"
joe2d92e852014-01-25 14:31:24 -08002
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"
joe93778a62014-02-15 13:22:14 -080011#include "frc971/control_loops/shooter/shooter_motor_plant.h"
joe2d92e852014-01-25 14:31:24 -080012
13namespace frc971 {
14namespace control_loops {
15
16ShooterMotor::ShooterMotor(control_loops::ShooterLoop *my_shooter)
17 : aos::control_loops::ControlLoop<control_loops::ShooterLoop>(my_shooter),
18 zeroed_joint_(MakeShooterLoop()) {
19 {
20 using ::frc971::constants::GetValues;
21 ZeroedJoint<1>::ConfigurationData config_data;
22
23 config_data.lower_limit = GetValues().shooter_lower_limit;
24 config_data.upper_limit = GetValues().shooter_upper_limit;
joe93778a62014-02-15 13:22:14 -080025 //config_data.hall_effect_start_position[0] =
26 // GetValues().shooter_hall_effect_start_position;
joe2d92e852014-01-25 14:31:24 -080027 config_data.zeroing_off_speed = GetValues().shooter_zeroing_off_speed;
28 config_data.zeroing_speed = GetValues().shooter_zeroing_speed;
joe2d92e852014-01-25 14:31:24 -080029 config_data.max_zeroing_voltage = 5.0;
30 config_data.deadband_voltage = 0.0;
31
32 zeroed_joint_.set_config_data(config_data);
33 }
34}
35
joef84ed442014-01-29 21:42:01 -080036// Positive is up, and positive power is up.
joe2d92e852014-01-25 14:31:24 -080037void ShooterMotor::RunIteration(
joe93778a62014-02-15 13:22:14 -080038 const ShooterLoop::Goal *goal,
joe2d92e852014-01-25 14:31:24 -080039 const control_loops::ShooterLoop::Position *position,
joe93778a62014-02-15 13:22:14 -080040 ShooterLoop::Output *output,
41 ShooterLoop::Status * status) {
joe2d92e852014-01-25 14:31:24 -080042
43 // Disable the motors now so that all early returns will return with the
44 // motors disabled.
45 if (output) {
46 output->voltage = 0;
47 }
48
49 ZeroedJoint<1>::PositionData transformed_position;
50 ZeroedJoint<1>::PositionData *transformed_position_ptr =
51 &transformed_position;
52 if (!position) {
53 transformed_position_ptr = NULL;
54 } else {
joe93778a62014-02-15 13:22:14 -080055 //transformed_position.position = position->pos;
56 //transformed_position.hall_effects[0] = position->hall_effect;
57 //transformed_position.hall_effect_positions[0] = position->calibration;
joe2d92e852014-01-25 14:31:24 -080058 }
59
60 const double voltage = zeroed_joint_.Update(transformed_position_ptr,
61 output != NULL,
62 goal->goal, 0.0);
63
64 if (position) {
joe93778a62014-02-15 13:22:14 -080065 LOG(DEBUG, "pos: hall: absolute: %f\n",
66 //position->pos,
67 //position->hall_effect ? "true" : "false",
joe2d92e852014-01-25 14:31:24 -080068 zeroed_joint_.absolute_position());
69 }
70
71 if (output) {
72 output->voltage = voltage;
73 }
74 status->done = ::std::abs(zeroed_joint_.absolute_position() - goal->goal) < 0.004;
75}
76
77} // namespace control_loops
78} // namespace frc971