Drivetrain now kind of works.

Change-Id: Ib8a518f849553949fff1095421cef1fd6f977f44
diff --git a/y2018/control_loops/drivetrain/drivetrain_base.cc b/y2018/control_loops/drivetrain/drivetrain_base.cc
index 67df3be..d589bc1 100644
--- a/y2018/control_loops/drivetrain/drivetrain_base.cc
+++ b/y2018/control_loops/drivetrain/drivetrain_base.cc
@@ -20,7 +20,7 @@
 const DrivetrainConfig &GetDrivetrainConfig() {
   static DrivetrainConfig kDrivetrainConfig{
       ::frc971::control_loops::drivetrain::ShifterType::HALL_EFFECT_SHIFTER,
-      ::frc971::control_loops::drivetrain::LoopType::OPEN_LOOP,
+      ::frc971::control_loops::drivetrain::LoopType::CLOSED_LOOP,
       ::frc971::control_loops::drivetrain::GyroType::SPARTAN_GYRO,
 
       ::y2018::control_loops::drivetrain::MakeDrivetrainLoop,
@@ -34,7 +34,8 @@
       kThreeStateDriveShifter, kThreeStateDriveShifter,
       true /* default_high_gear */, 0 /* down_offset if using constants use
                                    constants::GetValues().down_error */,
-      0.4 /* wheel_non_linearity */, 1.0 /* quickturn_wheel_multiplier */,
+      0.8 /* wheel_non_linearity */, 1.2 /* quickturn_wheel_multiplier */,
+      1.1 /* wheel_multiplier */,
   };
 
   return kDrivetrainConfig;
diff --git a/y2018/control_loops/python/drivetrain.py b/y2018/control_loops/python/drivetrain.py
index b630601..988ac74 100644
--- a/y2018/control_loops/python/drivetrain.py
+++ b/y2018/control_loops/python/drivetrain.py
@@ -14,28 +14,32 @@
 #robot radius needs confirming(set as distance of center wheels from each other)
 #J needs updating
 
-kDrivetrain = drivetrain.DrivetrainParams(J = 2.0,
-                                          mass = 54.4311,
-                                          robot_radius = 0.675 / 2.0,
-                                          wheel_radius = 0.127 / 2.0,
-                                          G_low = 46.0 / 60.0 * 20.0 / 48.0 * 14.0 / 62.0 ,
-                                          G_high = 62.0 / 44.0 * 20.0 / 48.0 * 14.0 / 62.0,
-                                          q_pos_low = 0.12,
-                                          q_pos_high = 0.14,
-                                          q_vel_low = 1.0,
-                                          q_vel_high = 0.95)
+kDrivetrain = drivetrain.DrivetrainParams(
+    J=2.5,
+    mass=68.0,
+    robot_radius=0.616 / 2.0,
+    wheel_radius=0.127 / 2.0,
+    G_low=46.0 / 60.0 * 20.0 / 48.0 * 14.0 / 62.0,
+    G_high=62.0 / 44.0 * 20.0 / 48.0 * 14.0 / 62.0,
+    q_pos_low=0.12,
+    q_pos_high=0.14,
+    q_vel_low=1.0,
+    q_vel_high=0.95,
+    controller_poles=[0.82, 0.82],
+)
+
 
 def main(argv):
-  argv = FLAGS(argv)
-  glog.init()
+    argv = FLAGS(argv)
+    glog.init()
 
-  if FLAGS.plot:
-    drivetrain.PlotDrivetrainMotions(kDrivetrain)
-  elif len(argv) != 5:
-    print "Expected .h file name and .cc file name"
-  else:
-    # Write the generated constants out to a file.
-    drivetrain.WriteDrivetrain(argv[1:3], argv[3:5], 'y2018', kDrivetrain)
+    if FLAGS.plot:
+        drivetrain.PlotDrivetrainMotions(kDrivetrain)
+    elif len(argv) != 5:
+        print "Expected .h file name and .cc file name"
+    else:
+        # Write the generated constants out to a file.
+        drivetrain.WriteDrivetrain(argv[1:3], argv[3:5], 'y2018', kDrivetrain)
 
 if __name__ == '__main__':
-  sys.exit(main(sys.argv))
+    sys.exit(main(sys.argv))
diff --git a/y2018/wpilib_interface.cc b/y2018/wpilib_interface.cc
index cc59769..aa13298 100644
--- a/y2018/wpilib_interface.cc
+++ b/y2018/wpilib_interface.cc
@@ -41,6 +41,7 @@
 #include "frc971/wpilib/dma.h"
 #include "frc971/wpilib/dma_edge_counting.h"
 #include "frc971/wpilib/encoder_and_potentiometer.h"
+#include "frc971/wpilib/gyro_sender.h"
 #include "frc971/wpilib/interrupt_edge_counting.h"
 #include "frc971/wpilib/joystick_sender.h"
 #include "frc971/wpilib/logging.q.h"
@@ -93,14 +94,18 @@
 }
 
 double drivetrain_translate(int32_t in) {
-  return static_cast<double>(in) /
-         Values::kDrivetrainEncoderCountsPerRevolution() *
-         Values::kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
+  return ((static_cast<double>(in) /
+           Values::kDrivetrainEncoderCountsPerRevolution()) *
+          (2.0 * M_PI)) *
+         Values::kDrivetrainEncoderRatio() *
+         control_loops::drivetrain::kWheelRadius;
 }
 
 double drivetrain_velocity_translate(double in) {
-  return (1.0 / in) / Values::kDrivetrainCyclesPerRevolution() *
-         Values::kDrivetrainEncoderRatio() * control_loops::drivetrain::kWheelRadius;
+  return (((1.0 / in) / Values::kDrivetrainCyclesPerRevolution()) *
+          (2.0 * M_PI)) *
+         Values::kDrivetrainEncoderRatio() *
+         control_loops::drivetrain::kWheelRadius;
 }
 
 double proximal_pot_translate(double voltage) {
@@ -833,9 +838,12 @@
     imu.set_reset(imu_reset.get());
     ::std::thread imu_thread(::std::ref(imu));
 
-// While as of 2/9/18 the drivetrain Victors are SPX, it appears as though they
-// are identical, as far as DrivetrainWriter is concerned, to the SP variety
-// so all the Victors are written as SPs.
+    ::frc971::wpilib::GyroSender gyro_sender;
+    ::std::thread gyro_thread(::std::ref(gyro_sender));
+
+    // While as of 2/9/18 the drivetrain Victors are SPX, it appears as though
+    // they are identical, as far as DrivetrainWriter is concerned, to the SP
+    // variety so all the Victors are written as SPs.
 
     DrivetrainWriter drivetrain_writer;
     drivetrain_writer.set_drivetrain_left_victor(
@@ -895,6 +903,9 @@
     imu.Quit();
     imu_thread.join();
 
+    gyro_sender.Quit();
+    gyro_thread.join();
+
     drivetrain_writer.Quit();
     drivetrain_writer_thread.join();
     superstructure_writer.Quit();