copied everything over from 2012 and removed all of the actual robot code except the drivetrain stuff
git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4078 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/frc971/output/AtomMotorWriter.cc b/frc971/output/AtomMotorWriter.cc
new file mode 100644
index 0000000..d0bf6f7
--- /dev/null
+++ b/frc971/output/AtomMotorWriter.cc
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "aos/aos_core.h"
+#include "aos/common/network/SendSocket.h"
+#include "aos/common/control_loop/Timing.h"
+#include "aos/common/messages/RobotState.q.h"
+#include "aos/atom_code/output/MotorOutput.h"
+
+#include "frc971/queues/Piston.q.h"
+#include "frc971/control_loops/DriveTrain.q.h"
+#include "frc971/constants.h"
+
+using ::frc971::control_loops::drivetrain;
+using ::frc971::control_loops::shifters;
+
+namespace frc971 {
+namespace output {
+
+class MotorWriter : public aos::MotorOutput {
+ void RunIteration() {
+ if (drivetrain.output.FetchLatest()) {
+ AddMotor(TALON, 7, -drivetrain.output->left_voltage / 12.0);
+ AddMotor(TALON, 4, drivetrain.output->right_voltage / 12.0);
+ } else {
+ AddMotor(TALON, 7, 0.0f);
+ AddMotor(TALON, 4, 0.0f);
+ }
+
+ if (shifters.FetchLatest()) {
+ AddSolenoid(1, shifters->set);
+ }
+ }
+};
+
+} // namespace output
+} // namespace frc971
+
+AOS_RUN(frc971::output::MotorWriter)
diff --git a/frc971/output/CRIOMotorWriter.cc b/frc971/output/CRIOMotorWriter.cc
new file mode 100644
index 0000000..b85ac4b
--- /dev/null
+++ b/frc971/output/CRIOMotorWriter.cc
@@ -0,0 +1,15 @@
+#include "WPILib/Victor.h"
+
+#include "aos/crio/motor_server/MotorOutput.h"
+#include "aos/aos_core.h"
+
+namespace frc971 {
+
+class MotorWriter : public aos::MotorOutput {
+ virtual void RunIteration() {
+ }
+};
+
+} // namespace frc971
+
+AOS_RUN(frc971::MotorWriter)
diff --git a/frc971/output/CameraServer.cc b/frc971/output/CameraServer.cc
new file mode 100644
index 0000000..96f698d
--- /dev/null
+++ b/frc971/output/CameraServer.cc
@@ -0,0 +1,81 @@
+#include <string.h>
+
+#include "aos/aos_core.h"
+#include "aos/atom_code/output/HTTPServer.h"
+#include "aos/atom_code/output/evhttp_ctemplate_emitter.h"
+#include "ctemplate/template.h"
+
+#include "frc971/constants.h"
+
+RegisterTemplateFilename(ROBOT_HTML, "robot.html.tpl");
+
+namespace frc971 {
+
+const char *const kPath = "/home/driver/robot_code/bin/";
+//const char *const kPath = "/home/brians/Desktop/git_frc971/2012/trunk/src/frc971/output";
+
+class CameraServer : public aos::http::HTTPServer {
+ public:
+ CameraServer() : HTTPServer(kPath, 8080), buf_(NULL) {
+ AddPage<CameraServer>("/robot.html", &CameraServer::RobotHTML, this);
+ }
+
+ private:
+ evbuffer *buf_;
+ bool Setup(evhttp_request *request, const char *content_type) {
+ if (evhttp_add_header(evhttp_request_get_output_headers(request),
+ "Content-Type", content_type) == -1) {
+ LOG(WARNING, "adding Content-Type failed\n");
+ evhttp_send_error(request, HTTP_INTERNAL, NULL);
+ return false;
+ }
+ if (buf_ == NULL) buf_ = evbuffer_new();
+ if (buf_ == NULL) {
+ LOG(WARNING, "evbuffer_new() failed\n");
+ evhttp_send_error(request, HTTP_INTERNAL, NULL);
+ return false;
+ }
+ return true;
+ }
+ void RobotHTML(evhttp_request *request) {
+ if (!Setup(request, "text/html")) return;
+
+ ctemplate::TemplateDictionary dict(ROBOT_HTML);
+ const char *host = evhttp_find_header(
+ evhttp_request_get_input_headers(request), "Host");
+ if (host == NULL) {
+ evhttp_send_error(request, HTTP_BADREQUEST, "no Host header");
+ return;
+ }
+ const char *separator = strchrnul(host, ':');
+ size_t length = separator - host;
+ // Don't include the last ':' (or the terminating '\0') or anything else
+ // after it.
+ dict.SetValue("HOST", ctemplate::TemplateString(host, length));
+
+ int center;
+ if (!constants::camera_center(¢er)) {
+ evhttp_send_error(request, HTTP_INTERNAL, NULL);
+ return;
+ }
+ dict.SetIntValue("CENTER", center);
+
+ aos::http::EvhttpCtemplateEmitter emitter(buf_);
+ if (!ctemplate::ExpandTemplate(ROBOT_HTML, ctemplate::STRIP_WHITESPACE,
+ &dict, &emitter)) {
+ LOG(ERROR, "expanding the template failed\n");
+ evhttp_send_error(request, HTTP_INTERNAL, NULL);
+ return;
+ }
+ if (emitter.error()) {
+ evhttp_send_error(request, HTTP_INTERNAL, NULL);
+ return;
+ }
+ evhttp_send_reply(request, HTTP_OK, NULL, buf_);
+ }
+};
+
+} // namespace frc971
+
+AOS_RUN_NRT(frc971::CameraServer)
+
diff --git a/frc971/output/SensorSender.cc b/frc971/output/SensorSender.cc
new file mode 100644
index 0000000..e2d2e51
--- /dev/null
+++ b/frc971/output/SensorSender.cc
@@ -0,0 +1,5 @@
+#include "aos/crio/motor_server/SensorSender.h"
+#include "frc971/queues/sensor_values.h"
+
+AOS_RUN_FORK(aos::SensorSender<frc971::sensor_values>, "971SS", 100)
+
diff --git a/frc971/output/output.gyp b/frc971/output/output.gyp
new file mode 100644
index 0000000..6cb28d1
--- /dev/null
+++ b/frc971/output/output.gyp
@@ -0,0 +1,59 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'CameraServer',
+ 'type': 'executable',
+ 'sources': [
+ 'CameraServer.cc',
+ ],
+ 'dependencies': [
+ '<(AOS)/build/aos.gyp:libaos',
+ '<(AOS)/atom_code/output/output.gyp:http_server',
+ '../frc971.gyp:common',
+ ],
+ 'copies': [
+ {
+ 'destination': '<(rsync_dir)',
+ 'files': [
+ 'robot.html.tpl',
+ ],
+ },
+ ],
+ },
+ {
+ 'target_name': 'MotorWriter',
+ 'type': '<(aos_target)',
+ 'conditions': [
+ ['OS=="atom"', {
+ 'sources': ['AtomMotorWriter.cc'],
+ 'dependencies': [
+ '../frc971.gyp:common',
+ '<(AOS)/atom_code/output/output.gyp:motor_output',
+ '<(AOS)/atom_code/messages/messages.gyp:messages',
+ ],
+ }, {
+ 'sources': ['CRIOMotorWriter.cc'],
+ }
+ ],
+ ],
+ 'dependencies': [
+ '<(AOS)/build/aos.gyp:libaos',
+ '<(AOS)/common/common.gyp:controls',
+ '<(DEPTH)/frc971/control_loops/control_loops.gyp:control_loops',
+ '<(DEPTH)/frc971/queues/queues.gyp:queues',
+ '<(AOS)/common/network/network.gyp:socket',
+ ],
+ },
+ {
+ 'target_name': 'SensorSender',
+ 'type': '<(aos_target)',
+ 'sources': [
+ 'SensorSender.cc',
+ ],
+ 'dependencies': [
+ '<(AOS)/build/aos.gyp:libaos',
+ '<(AOS)/common/network/network.gyp:socket',
+ ],
+ },
+ ],
+}
diff --git a/frc971/output/robot.html.tpl b/frc971/output/robot.html.tpl
new file mode 100644
index 0000000..7ae51a6
--- /dev/null
+++ b/frc971/output/robot.html.tpl
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>971 Camera Code: Robot Stream</title>
+ <style type="text/css">
+ #body {
+ display: block;
+ margin: 0px;
+ margin-top: 0px;
+ margin-right: 0px;
+ margin-bottom: 0px;
+ margin-left: 0px;
+ }
+ #img {
+ position: absolute;
+ left: 50%;
+ top: 0%;
+ margin: 0 0 0 -320px;
+ }
+ #center {
+ left: 50%;
+ position: absolute;
+ width: 2px;
+ height: 100%;
+ background-color: red;
+ }
+ #middle {
+ top: 240px;
+ margin-top: -1px;
+ width: 100%;
+ position: absolute;
+ height: 2px;
+ background-color: red;
+ }
+ #footer {
+ top: 482px;
+ left: 10px;
+ position: absolute;
+ }
+ #center {
+ margin-left: {{CENTER}}px;
+ }
+ </style>
+ </head>
+ <body id="body">
+ <img id="img" src="http://{{HOST}}:9714" />
+ <div id="center"></div>
+ <div id="middle"></div>
+ <div id="footer">
+ <!--<form>
+ <input type="button" value="Camera Controls"
+ onclick="window.open('control.htm', 'Camera_Controls')">
+ </form>-->
+ </div>
+ </body>
+</html>