Merge "tune the claw"
diff --git a/aos/build/build.py b/aos/build/build.py
index 2e456f1..5be0950 100755
--- a/aos/build/build.py
+++ b/aos/build/build.py
@@ -670,6 +670,7 @@
                            Defaults to everything.
   extra_flag...            Extra flags associated with the targets.
                            --gtest_*: Arguments to pass on to tests.
+                           --print_logs, --log_file=*: More test arguments.
 
 Specifying targets:
  Targets are combinations of architecture, compiler, and debug flags. Which
@@ -755,12 +756,13 @@
       continue
     if arg == '-h' or arg == '--help':
       print_help(0)
-    if re.match('^--gtest_.*$', arg):
+    if (re.match('^--gtest_.*$', arg) or arg == '--print-logs' or
+        re.match('^--log_file=.*$', arg)):
       if args.action_name == 'tests':
         args.extra_flags.append(arg)
         continue
       else:
-        print_help(1, '--gtest_* is only valid for tests')
+        print_help(1, '%s is only valid for tests' % arg)
     if args.platform:
       args.targets.append(arg)
     else:
diff --git a/aos/build/externals.gyp b/aos/build/externals.gyp
index 315f0bf..2bfe241 100644
--- a/aos/build/externals.gyp
+++ b/aos/build/externals.gyp
@@ -136,11 +136,9 @@
       ],
       'dependencies': [
         'gtest_prod',
-        '<(AOS)/common/common.gyp:queue_testutils',
       ],
       'export_dependent_settings': [
         'gtest_prod',
-        '<(AOS)/common/common.gyp:queue_testutils',
       ],
       'cflags!': ['-Werror'],
       'direct_dependent_settings': {
diff --git a/aos/common/event_test.cc b/aos/common/event_test.cc
index fff7522..d8671eb 100644
--- a/aos/common/event_test.cc
+++ b/aos/common/event_test.cc
@@ -34,8 +34,9 @@
 // Tests that tsan understands that events establish a happens-before
 // relationship.
 TEST_F(EventTest, ThreadSanitizer) {
-  for (int i = 0; i < 1000; ++i) {
+  for (int i = 0; i < 3000; ++i) {
     int variable = 0;
+    test_event.Clear();
     ::std::thread thread([this, &variable]() {
       test_event.Wait();
       --variable;
@@ -50,12 +51,16 @@
 // Tests that an event blocks correctly.
 TEST_F(EventTest, Blocks) {
   time::Time start_time, finish_time;
-  ::std::thread thread([this, &start_time, &finish_time]() {
+  // Without this, it sometimes manages to fail under tsan.
+  Event started;
+  ::std::thread thread([this, &start_time, &finish_time, &started]() {
     start_time = time::Time::Now();
+    started.Set();
     test_event.Wait();
     finish_time = time::Time::Now();
   });
   static const time::Time kWaitTime = time::Time::InSeconds(0.05);
+  started.Wait();
   time::SleepFor(kWaitTime);
   test_event.Set();
   thread.join();
diff --git a/aos/externals/gtest/gtest_main.cc b/aos/externals/gtest/gtest_main.cc
index 024c502..0f6b60e 100644
--- a/aos/externals/gtest/gtest_main.cc
+++ b/aos/externals/gtest/gtest_main.cc
@@ -2,7 +2,18 @@
 #include <getopt.h>
 
 #include "gtest/gtest.h"
-#include "aos/common/queue_testutils.h"
+
+namespace aos {
+namespace common {
+namespace testing {
+
+// Actually declared/defined in aos/common/queue_testutils.
+void SetLogFileName(const char* filename) __attribute__((weak));
+void ForcePrintLogsDuringTests() __attribute__((weak));
+
+}  // namespace testing
+}  // namespace common
+}  // namespace aos
 
 GTEST_API_ int main(int argc, char **argv) {
   static const struct option long_options[] = {
@@ -36,11 +47,15 @@
         break;
 
       case 'p':
-        aos::common::testing::ForcePrintLogsDuringTests();
+        if (::aos::common::testing::ForcePrintLogsDuringTests) {
+          ::aos::common::testing::ForcePrintLogsDuringTests();
+        }
         break;
 
       case 'o':
-        aos::common::testing::SetLogFileName(optarg);
+        if (::aos::common::testing::SetLogFileName) {
+          ::aos::common::testing::SetLogFileName(optarg);
+        }
         break;
 
       case '?':
diff --git a/aos/linux_code/ipc_lib/aos_sync.cc b/aos/linux_code/ipc_lib/aos_sync.cc
index ffd1061..311d88d 100644
--- a/aos/linux_code/ipc_lib/aos_sync.cc
+++ b/aos/linux_code/ipc_lib/aos_sync.cc
@@ -411,6 +411,10 @@
       return -1;
     }
   }
+#ifdef AOS_SANITIZER_thread
+  // Help tsan figure out that we're synchronizing on this.
+  __sync_add_and_fetch(m, 0);
+#endif
   return 0;
 }
 
diff --git a/frc971/control_loops/claw/claw.q b/frc971/control_loops/claw/claw.q
index 7696d3b..8da1c20 100644
--- a/frc971/control_loops/claw/claw.q
+++ b/frc971/control_loops/claw/claw.q
@@ -14,11 +14,11 @@
     // Angle of wrist joint.
     double angle;
     // Angular velocity of wrist.
-    double angular_velocity;
+    float angular_velocity;
     // Maximum profile velocity, or 0 for the default.
-    double max_velocity;
+    float max_velocity;
     // Maximum profile acceleration, or 0 for the default.
-    double max_acceleration;
+    float max_acceleration;
     // Voltage of intake rollers. Positive means sucking in, negative means
     // spitting out.
     double intake;
@@ -54,11 +54,11 @@
     // Estimated angle of wrist joint.
     double angle;
     // Estimated angular velocity of wrist.
-    double angular_velocity;
+    float angular_velocity;
 
     // Goal angle of wrist joint.
     double goal_angle;
-    double goal_velocity;
+    float goal_velocity;
     // Voltage of intake rollers. Positive means sucking in, negative means
     // spitting out.
     double intake;
diff --git a/frc971/control_loops/fridge/fridge.q b/frc971/control_loops/fridge/fridge.q
index 637f499..257374d 100644
--- a/frc971/control_loops/fridge/fridge.q
+++ b/frc971/control_loops/fridge/fridge.q
@@ -42,19 +42,19 @@
     double height;
 
     // Angular velocity of the arm.
-    double angular_velocity;
+    float angular_velocity;
     // Linear velocity of the elevator.
-    double velocity;
+    float velocity;
 
     // Maximum arm profile angular velocity or 0 for the default.
-    double max_angular_velocity;
+    float max_angular_velocity;
     // Maximum elevator profile velocity or 0 for the default.
-    double max_velocity;
+    float max_velocity;
 
     // Maximum arm profile acceleration or 0 for the default.
-    double max_angular_acceleration;
+    float max_angular_acceleration;
     // Maximum elevator profile acceleration or 0 for the default.
-    double max_acceleration;
+    float max_acceleration;
 
     // X position of the fridge.
     double x;
@@ -62,19 +62,19 @@
     double y;
 
     // Velocity of the x position of the fridge.
-    double x_velocity;
+    float x_velocity;
     // Velocity of the y position of the fridge.
-    double y_velocity;
+    float y_velocity;
 
     // Maximum x profile velocity or 0 for the default.
-    double max_x_velocity;
+    float max_x_velocity;
     // Maximum y profile velocity or 0 for the default.
-    double max_y_velocity;
+    float max_y_velocity;
 
     // Maximum x profile acceleration or 0 for the default.
-    double max_x_acceleration;
+    float max_x_acceleration;
     // Maximum y profile acceleration or 0 for the default.
-    double max_y_acceleration;
+    float max_y_acceleration;
 
     // TODO(austin): Do I need acceleration here too?
 
@@ -93,34 +93,34 @@
     // Estimated angle of the arm.
     double angle;
     // Estimated angular velocity of the arm.
-    double angular_velocity;
+    float angular_velocity;
     // Estimated height of the elevator.
     double height;
     // Estimated velocity of the elvator.
-    double velocity;
+    float velocity;
     // state of the grabber pistons
     GrabberPistons grabbers;
 
     // Goal angle and velocity of the arm.
     double goal_angle;
-    double goal_angular_velocity;
+    float goal_angular_velocity;
     // Goal height and velocity of the elevator.
     double goal_height;
-    double goal_velocity;
+    float goal_velocity;
 
     // Estimated X/Y position of the fridge.
     // These are translated directly from the height/angle statuses.
     double x;
     double y;
-    double x_velocity;
-    double y_velocity;
+    float x_velocity;
+    float y_velocity;
 
     // X/Y goals of the fridge.
     // These are translated directly from the height/angle goals.
     double goal_x;
     double goal_y;
-    double goal_x_velocity;
-    double goal_y_velocity;
+    float goal_x_velocity;
+    float goal_y_velocity;
 
     // If true, we have aborted.
     bool estopped;