switched from fitpc/atom to prime/linux
Also removed a few old things that had nothing reasonable to be changed
to.
diff --git a/aos/prime/input/input.gyp b/aos/prime/input/input.gyp
new file mode 100644
index 0000000..8aba065
--- /dev/null
+++ b/aos/prime/input/input.gyp
@@ -0,0 +1,21 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'joystick_input',
+ 'type': 'static_library',
+ 'sources': [
+ 'joystick_input.cc',
+ ],
+ 'dependencies': [
+ '<(AOS)/common/input/input.gyp:driver_station_data',
+ '<(AOS)/common/messages/messages.gyp:aos_queues',
+ '<(AOS)/common/network/network.gyp:socket',
+ '<(EXTERNALS):WPILib-NetworkRobotValues',
+ '<(AOS)/build/aos.gyp:logging',
+ ],
+ 'export_dependent_settings': [
+ '<(AOS)/common/input/input.gyp:driver_station_data',
+ ],
+ },
+ ],
+}
diff --git a/aos/prime/input/joystick_input.cc b/aos/prime/input/joystick_input.cc
new file mode 100644
index 0000000..6439dbc
--- /dev/null
+++ b/aos/prime/input/joystick_input.cc
@@ -0,0 +1,92 @@
+#include "aos/prime/input/joystick_input.h"
+
+#include <string.h>
+
+#include "aos/externals/WPILib/WPILib/NetworkRobot/NetworkRobotValues.h"
+
+#include "aos/common/network_port.h"
+#include "aos/common/network/ReceiveSocket.h"
+#include "aos/common/messages/RobotState.q.h"
+#include "aos/common/logging/logging.h"
+
+namespace aos {
+namespace input {
+
+void JoystickInput::Run() {
+ ReceiveSocket sock(NetworkPort::kDS);
+
+ NetworkRobotJoysticks joysticks;
+ char buffer[sizeof(joysticks) + ::buffers::kOverhead];
+ driver_station::Data data;
+
+ while (true) {
+ int received = sock.Receive(buffer, sizeof(buffer));
+ if (received == -1) {
+ LOG(WARNING, "socket receive failed with %d: %s\n",
+ errno, strerror(errno));
+ continue;
+ }
+
+ if (!joysticks.DeserializeFrom(buffer, received)) {
+ LOG(WARNING, "deserializing data from %zd bytes failed\n", received);
+ continue;
+ }
+
+ if (!robot_state.MakeWithBuilder()
+ .enabled(joysticks.control.enabled())
+ .autonomous(joysticks.control.autonomous())
+ .team_id(joysticks.team_number)
+ .Send()) {
+ LOG(WARNING, "sending robot_state failed\n");
+ } else {
+ LOG(DEBUG, "sent robot_state{%s, %s, %hu}\n",
+ joysticks.control.enabled() ? "enabled" : "disabled",
+ joysticks.control.autonomous() ? "auto" : "not auto",
+ joysticks.team_number);
+ }
+
+ data.Update(joysticks);
+
+ {
+ using driver_station::JoystickFeature;
+ using driver_station::ButtonLocation;
+ for (int joystick = 1; joystick <= JoystickFeature::kJoysticks;
+ ++joystick) {
+ for (int button = 1; button <= ButtonLocation::kButtons; ++button) {
+ ButtonLocation location(joystick, button);
+ if (data.PosEdge(location)) {
+ LOG(INFO, "PosEdge(%d, %d)\n", joystick, button);
+ }
+ if (data.NegEdge(location)) {
+ LOG(INFO, "NegEdge(%d, %d)\n", joystick, button);
+ }
+ }
+ }
+
+ using driver_station::ControlBit;
+ if (data.PosEdge(ControlBit::kFmsAttached)) {
+ LOG(INFO, "PosEdge(kFmsAttached)\n");
+ }
+ if (data.NegEdge(ControlBit::kFmsAttached)) {
+ LOG(INFO, "NegEdge(kFmsAttached)\n");
+ }
+ if (data.PosEdge(ControlBit::kAutonomous)) {
+ LOG(INFO, "PosEdge(kAutonomous)\n");
+ }
+ if (data.NegEdge(ControlBit::kAutonomous)) {
+ LOG(INFO, "NegEdge(kAutonomous)\n");
+ }
+ if (data.PosEdge(ControlBit::kEnabled)) {
+ LOG(INFO, "PosEdge(kEnabled)\n");
+ }
+ if (data.NegEdge(ControlBit::kEnabled)) {
+ LOG(INFO, "NegEdge(kEnabled)\n");
+ }
+ }
+
+ RunIteration(data);
+ }
+}
+
+} // namespace input
+} // namespace aos
diff --git a/aos/prime/input/joystick_input.h b/aos/prime/input/joystick_input.h
new file mode 100644
index 0000000..17fdbbe
--- /dev/null
+++ b/aos/prime/input/joystick_input.h
@@ -0,0 +1,26 @@
+#ifndef AOS_LINUX_CODE_INPUT_JOYSTICKS_INPUT_H_
+#define AOS_LINUX_CODE_INPUT_JOYSTICKS_INPUT_H_
+
+#include "aos/common/input/driver_station_data.h"
+
+namespace aos {
+namespace input {
+
+// A class for handling joystick packet values.
+// It will call RunIteration each time a new packet is received.
+//
+// This class automatically handles updating ::aos::robot_state and logging (at
+// INFO) button edges.
+class JoystickInput {
+ public:
+ void Run();
+
+ private:
+ // Subclasses should do whatever they want with data here.
+ virtual void RunIteration(const driver_station::Data &data) = 0;
+};
+
+} // namespace input
+} // namespace aos
+
+#endif // AOS_LINUX_CODE_INPUT_JOYSTICKS_INPUT_H_
diff --git a/aos/prime/output/motor_output.cc b/aos/prime/output/motor_output.cc
new file mode 100644
index 0000000..a532183
--- /dev/null
+++ b/aos/prime/output/motor_output.cc
@@ -0,0 +1,99 @@
+#include "aos/prime/output/motor_output.h"
+
+#include <math.h>
+
+#include "aos/common/control_loop/Timing.h"
+#include "aos/common/logging/logging.h"
+#include "aos/common/network_port.h"
+
+namespace aos {
+
+// 255 = 2.5ms, 0 = 0.5ms (or something close to that)
+// got 211->210 as first transition that made a speed difference and 53->54 on
+// the other side
+// going 2 to each side to make sure we get the full range
+const MotorOutput::MotorControllerBounds MotorOutput::kTalonBounds
+ {213, 135, 132, 129, 50};
+const MotorOutput::MotorControllerBounds MotorOutput::kVictorBounds
+ {210, 138, 132, 126, 56};
+
+uint8_t MotorOutput::MotorControllerBounds::Map(double value) const {
+ if (value == 0.0) return kCenter;
+ if (value > 12.0) return Map(12.0);
+ if (value < -12.0) return Map(-12.0);
+ uint8_t r;
+ if (value > 0.0) {
+ r = static_cast<uint8_t>(kDeadbandMax + (value * (kMax - kDeadbandMax)) +
+ 0.5);
+ } else {
+ r = static_cast<uint8_t>(kDeadbandMin + (value * (kDeadbandMin - kMin)) +
+ 0.5);
+ }
+ if (r < kMin) return kMin;
+ if (r > kMax) return kMax;
+ return r;
+}
+
+MotorOutput::MotorOutput()
+ : socket_(NetworkPort::kMotors, ::aos::NetworkAddress::kCRIO) {
+}
+
+void MotorOutput::Run() {
+ while (true) {
+ time::PhasedLoopXMS(5, 1000);
+
+ values_.digital_module = -1;
+ // 0 means output disabled.
+ memset(&values_.pwm_outputs, 0x00, sizeof(values_.pwm_outputs));
+ values_.digital_output_enables = 0;
+ values_.digital_output_values = 0;
+ values_.pressure_switch_channel = 0;
+ values_.compressor_channel = 0;
+ values_.solenoid_module = -1;
+ values_.solenoid_values = 0;
+
+ RunIteration();
+
+ char buffer[sizeof(values_) + ::buffers::kOverhead];
+ ssize_t size = values_.SerializeTo(buffer, sizeof(buffer));
+ if (size <= 0) {
+ LOG(WARNING, "serializing outputs failed\n");
+ continue;
+ }
+ if (socket_.Send(buffer, size) != size) {
+ LOG(WARNING, "sending outputs failed\n");
+ continue;
+ } else {
+ LOG(DEBUG, "sent outputs\n");
+ }
+ }
+}
+
+void MotorOutput::SetSolenoid(uint8_t channel, bool set) {
+ if (set) {
+ values_.solenoid_values |= 1 << (channel - 1);
+ } else {
+ values_.solenoid_values &= ~(1 << (channel - 1));
+ }
+}
+
+void MotorOutput::SetPWMOutput(uint8_t channel, double value,
+ const MotorControllerBounds &bounds) {
+ values_.pwm_outputs[channel - 1] = bounds.Map(value);
+}
+
+void MotorOutput::DisablePWMOutput(uint8_t channel) {
+ values_.pwm_outputs[channel - 1] = 0;
+}
+
+void MotorOutput::SetDigitalOutput(uint8_t channel, bool value) {
+ const uint8_t shift_amount = 15 - channel;
+ values_.digital_output_enables |= 1 << shift_amount;
+ if (value) {
+ values_.digital_output_values |= 1 << shift_amount;
+ } else {
+ values_.digital_output_values &= ~(1 << shift_amount);
+ }
+}
+
+} // namespace aos
diff --git a/aos/prime/output/motor_output.h b/aos/prime/output/motor_output.h
new file mode 100644
index 0000000..53bdc83
--- /dev/null
+++ b/aos/prime/output/motor_output.h
@@ -0,0 +1,70 @@
+#ifndef AOS_LINUX_CODE_OUTPUT_MOTOR_OUTPUT_H_
+#define AOS_LINUX_CODE_OUTPUT_MOTOR_OUTPUT_H_
+
+#include <stdint.h>
+#include <string.h>
+#include <algorithm>
+#include <string>
+
+#include "aos/common/network/SendSocket.h"
+#include "aos/common/byteorder.h"
+#include "aos/common/type_traits.h"
+#include "aos/externals/WPILib/WPILib/NetworkRobot/NetworkRobotValues.h"
+
+namespace aos {
+
+// A class for sending output values to a cRIO.
+// values_ gets completely reset each time through, so RunIteration() needs to
+// set everything each time.
+class MotorOutput {
+ public:
+ MotorOutput();
+ void Run();
+
+ // A container for holding the constants that WPILib uses for each type of
+ // motor controller to map floating point values to 1-byte PWM values to
+ // actually use.
+ struct MotorControllerBounds {
+ // What 1.0 maps to.
+ const uint8_t kMax;
+ // The smallest value to map a positive speed to.
+ const uint8_t kDeadbandMax;
+ // What 0.0 maps to.
+ const uint8_t kCenter;
+ // The biggest value to map a negative speed to.
+ const uint8_t kDeadbandMin;
+ // What -1.0 maps to.
+ const uint8_t kMin;
+
+ // Applies the mapping.
+ uint8_t Map(double value) const;
+ };
+
+ protected:
+ // Brian got the values here by trying values with hardware on 11/23/12.
+ static const MotorControllerBounds kTalonBounds;
+ // Taken from WPILib.
+ static const MotorControllerBounds kVictorBounds;
+
+ // Helper methods for filling out values_.
+ // All channels are the 1-indexed numbers that usually go into WPILib.
+ void SetSolenoid(uint8_t channel, bool set);
+ void SetPWMOutput(uint8_t channel, double value,
+ const MotorControllerBounds &bounds);
+ void DisablePWMOutput(uint8_t channel);
+ void SetDigitalOutput(uint8_t channel, bool value);
+
+ // The data that's going to get sent over.
+ // Gets reset (everything set so that it won't do anything) each time through.
+ NetworkRobotMotors values_;
+
+ private:
+ // Subclasses need to actually fill out values_ here.
+ virtual void RunIteration() = 0;
+
+ SendSocket socket_;
+};
+
+} // namespace aos
+
+#endif
diff --git a/aos/prime/output/motor_output_test.cc b/aos/prime/output/motor_output_test.cc
new file mode 100644
index 0000000..52a5091
--- /dev/null
+++ b/aos/prime/output/motor_output_test.cc
@@ -0,0 +1,21 @@
+#include "aos/prime/output/motor_output.h"
+
+#include "gtest/gtest.h"
+
+namespace aos {
+namespace testing {
+
+TEST(MotorControllerBoundsTest, Limits) {
+ MotorOutput::MotorControllerBounds test_bounds
+ {200, 135, 128, 126, 110};
+ EXPECT_EQ(test_bounds.Map(1.0), test_bounds.kMax);
+ EXPECT_EQ(test_bounds.Map(-1.0), test_bounds.kMin);
+ EXPECT_EQ(test_bounds.Map(0.0), test_bounds.kCenter);
+ EXPECT_EQ(test_bounds.Map(0.55), 171);
+ EXPECT_EQ(test_bounds.Map(0.5), 168);
+ EXPECT_EQ(test_bounds.Map(0.45), 164);
+ EXPECT_EQ(test_bounds.Map(-0.5), 118);
+}
+
+} // namespace testing
+} // namespace aos
diff --git a/aos/prime/output/output.gyp b/aos/prime/output/output.gyp
new file mode 100644
index 0000000..b1e4b79
--- /dev/null
+++ b/aos/prime/output/output.gyp
@@ -0,0 +1,32 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'motor_output',
+ 'type': 'static_library',
+ 'sources': [
+ 'motor_output.cc',
+ ],
+ 'dependencies': [
+ '<(AOS)/common/network/network.gyp:socket',
+ '<(AOS)/common/common.gyp:timing',
+ '<(EXTERNALS):WPILib-NetworkRobotValues',
+ '<(AOS)/build/aos.gyp:logging',
+ ],
+ 'export_dependent_settings': [
+ '<(AOS)/common/network/network.gyp:socket',
+ '<(EXTERNALS):WPILib-NetworkRobotValues',
+ ],
+ },
+ {
+ 'target_name': 'motor_output_test',
+ 'type': 'executable',
+ 'sources': [
+ 'motor_output_test.cc',
+ ],
+ 'dependencies': [
+ 'motor_output',
+ '<(EXTERNALS):gtest',
+ ],
+ },
+ ],
+}