blob: dfb726973276b9507a0cea08398b3282c2077e4b [file] [log] [blame]
Comran Morshed41ed7c22015-11-04 21:03:37 +00001#ifndef Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_
2#define Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_
Comran Morshede9b12922015-11-04 19:46:48 +00003
4#include "Eigen/Dense"
5
6#include "aos/common/controls/polytope.h"
7#include "aos/common/controls/control_loop.h"
8#include "aos/common/controls/polytope.h"
9#include "aos/common/util/log_interval.h"
Comran Morshede9b12922015-11-04 19:46:48 +000010
Comran Morshed41ed7c22015-11-04 21:03:37 +000011#include "frc971/shifter_hall_effect.h"
12#include "y2014_bot3/control_loops/drivetrain/drivetrain.q.h"
13
14namespace y2014_bot3 {
Comran Morshede9b12922015-11-04 19:46:48 +000015namespace control_loops {
16
Comran Morshed41ed7c22015-11-04 21:03:37 +000017// Constants
18// TODO(comran): Get actual constants.
19constexpr double kDrivetrainTurnWidth = 0.63;
Comran Morshed41ed7c22015-11-04 21:03:37 +000020constexpr double kDrivetrainEncoderRatio = 18.0 / 44.0;
21constexpr double kDrivetrainHighGearRatio =
22 kDrivetrainEncoderRatio * 18.0 / 60.0;
23constexpr double kDrivetrainLowGearRatio = kDrivetrainHighGearRatio;
24const ::frc971::constants::ShifterHallEffect kDrivetrainRightShifter{
25 555, 657, 660, 560, 0.2, 0.7};
26const ::frc971::constants::ShifterHallEffect kDrivetrainLeftShifter{
27 555, 660, 644, 552, 0.2, 0.7};
28// End constants
29
Comran Morshede9b12922015-11-04 19:46:48 +000030class DrivetrainLoop
Comran Morshed41ed7c22015-11-04 21:03:37 +000031 : public aos::controls::ControlLoop<control_loops::DrivetrainQueue> {
Comran Morshede9b12922015-11-04 19:46:48 +000032 public:
33 // Constructs a control loop which can take a Drivetrain or defaults to the
Comran Morshed41ed7c22015-11-04 21:03:37 +000034 // drivetrain at y2014_bot3::control_loops::drivetrain
35 explicit DrivetrainLoop(control_loops::DrivetrainQueue *my_drivetrain =
36 &control_loops::drivetrain_queue)
37 : aos::controls::ControlLoop<control_loops::DrivetrainQueue>(
38 my_drivetrain) {
Comran Morshede9b12922015-11-04 19:46:48 +000039 ::aos::controls::HPolytope<0>::Init();
40 }
41
42 protected:
43 // Executes one cycle of the control loop.
44 virtual void RunIteration(
Comran Morshed41ed7c22015-11-04 21:03:37 +000045 const control_loops::DrivetrainQueue::Goal *goal,
46 const control_loops::DrivetrainQueue::Position *position,
47 control_loops::DrivetrainQueue::Output *output,
48 control_loops::DrivetrainQueue::Status *status);
Comran Morshede9b12922015-11-04 19:46:48 +000049
50 typedef ::aos::util::SimpleLogInterval SimpleLogInterval;
51 SimpleLogInterval no_position_ = SimpleLogInterval(
52 ::aos::time::Time::InSeconds(0.25), WARNING, "no position");
53};
54
55} // namespace control_loops
Comran Morshed41ed7c22015-11-04 21:03:37 +000056} // namespace y2014_bot3
Comran Morshede9b12922015-11-04 19:46:48 +000057
Comran Morshed41ed7c22015-11-04 21:03:37 +000058#endif // Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_