blob: 0565820ab4e3c282ad777082687d831b6f08d0d7 [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;
20constexpr double kDrivetrainDoneDistance = 0.02;
21constexpr double kDrivetrainEncoderRatio = 18.0 / 44.0;
22constexpr double kDrivetrainHighGearRatio =
23 kDrivetrainEncoderRatio * 18.0 / 60.0;
24constexpr double kDrivetrainLowGearRatio = kDrivetrainHighGearRatio;
25const ::frc971::constants::ShifterHallEffect kDrivetrainRightShifter{
26 555, 657, 660, 560, 0.2, 0.7};
27const ::frc971::constants::ShifterHallEffect kDrivetrainLeftShifter{
28 555, 660, 644, 552, 0.2, 0.7};
29// End constants
30
Comran Morshede9b12922015-11-04 19:46:48 +000031class DrivetrainLoop
Comran Morshed41ed7c22015-11-04 21:03:37 +000032 : public aos::controls::ControlLoop<control_loops::DrivetrainQueue> {
Comran Morshede9b12922015-11-04 19:46:48 +000033 public:
34 // Constructs a control loop which can take a Drivetrain or defaults to the
Comran Morshed41ed7c22015-11-04 21:03:37 +000035 // drivetrain at y2014_bot3::control_loops::drivetrain
36 explicit DrivetrainLoop(control_loops::DrivetrainQueue *my_drivetrain =
37 &control_loops::drivetrain_queue)
38 : aos::controls::ControlLoop<control_loops::DrivetrainQueue>(
39 my_drivetrain) {
Comran Morshede9b12922015-11-04 19:46:48 +000040 ::aos::controls::HPolytope<0>::Init();
41 }
42
43 protected:
44 // Executes one cycle of the control loop.
45 virtual void RunIteration(
Comran Morshed41ed7c22015-11-04 21:03:37 +000046 const control_loops::DrivetrainQueue::Goal *goal,
47 const control_loops::DrivetrainQueue::Position *position,
48 control_loops::DrivetrainQueue::Output *output,
49 control_loops::DrivetrainQueue::Status *status);
Comran Morshede9b12922015-11-04 19:46:48 +000050
51 typedef ::aos::util::SimpleLogInterval SimpleLogInterval;
52 SimpleLogInterval no_position_ = SimpleLogInterval(
53 ::aos::time::Time::InSeconds(0.25), WARNING, "no position");
54};
55
56} // namespace control_loops
Comran Morshed41ed7c22015-11-04 21:03:37 +000057} // namespace y2014_bot3
Comran Morshede9b12922015-11-04 19:46:48 +000058
Comran Morshed41ed7c22015-11-04 21:03:37 +000059#endif // Y2014_BOT3_CONTROL_LOOPS_DRIVETRAIN_H_