Tufts Hybrid Racing Sensor Node

Files at this revision

API Documentation at this revision

Comitter:
wsalis01
Date:
Sun Apr 15 00:12:28 2012 +0000
Parent:
0:1f9ada316815
Commit message:
Initial Commit

Changed in this revision

CANProtocol.lib Show diff for this revision Revisions of this file
SensorNode.cpp Show annotated file Show diff for this revision Revisions of this file
SensorNode.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/CANProtocol.lib	Thu Jan 12 20:44:36 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/wsalis01/code/CANProtocol/#3f7b957d3617
--- a/SensorNode.cpp	Thu Jan 12 20:44:36 2012 +0000
+++ b/SensorNode.cpp	Sun Apr 15 00:12:28 2012 +0000
@@ -1,98 +1,99 @@
-/*
- * File: SensorNode/SensorNode.cpp
- * Author: William Jessup Salisbury
- * Company: Tufts Hybrid Racing Team
- * Copyright: CC BY-NC-SA 3.0
- * Date: 1/12/2012
- */
-
-#include "mbed.h"
-#include "CANProtocol.h"
-#include "SensorNode.h"
-
-SensorNode::SensorNode() : _leftWheel(LW_PIN), _rightWheel(RW_PIN), _can(CAN_RX, CAN_TX), _console(USBTX, USBRX), _leftTicks(0), _rightTicks(0), _leftRevolutions(0), _rightRevolutions(0), _syncID(0)  {
-    /* InterruptIn initialization */
-    _leftWheel.mode(PullUp);
-    _leftWheel.fall(this, &SensorNode::leftTick);
-    _rightWheel.mode(PullUp);
-    _rightWheel.fall(this, &SensorNode::rightTick);
-    
-    /* CAN initialization */
-    _can.attach(this, &SensorNode::canReceive);
-    
-    /* Ticker initialization */
-    _statusTicker.attach(this, &SensorNode::canSend, tickerTimeout);
-    
-    /* Hello, World! */
-    _console.printf("%s\r\n", "SensorNode instantiated");
-}
-
-SensorNode::~SensorNode() {
-    _statusTicker.detach();
-}
-
-void SensorNode::leftTick() {
-    if ( (++_leftTicks % ticksPerRevolution) == 0 ) {
-        _leftTicks = 0;
-        ++_leftRevolutions;
-    }
-}
-
-void SensorNode::rightTick() {
-    if ( (++_rightTicks % ticksPerRevolution) == 0 ) {
-        _rightTicks = 0;
-        ++_rightRevolutions;
-    }
-}
-
-void SensorNode::canSend() {
-    CANMessage msg;
-    msg.id = CAN_STATUS;
-    msg.len = 8;
-    msg.data[0] = 0xD;
-    msg.data[1] = 0xE;
-    msg.data[2] = 0xA;
-    msg.data[3] = 0xD;
-    msg.data[4] = 0xB;
-    msg.data[5] = 0xE;
-    msg.data[6] = 0xE;
-    msg.data[7] = 0xF;
-    if (_can.write(msg)) {
-        _console.printf("%s\r\n", "Message sent.");
-    } else {
-        _console.printf("%s\r\n", "Message send failure.");
-    }
-}
-
-void SensorNode::canReceive() {
-    CANMessage msg;
-
-    if (_can.read(msg)) {
-        _console.printf("%s\n", "Message received.");
-        switch (msg.id) {
-            case CAN_RESET:
-                Reset();
-                break;
-
-            case CAN_SYNC:
-                _syncID = msg.data[0];
-
-                break;
-
-            default:
-                _console.printf("%s\r\n", "Message decode failure.");
-                break;
-        }
-    } else {
-        _console.printf("%s\r\n", "Message recieve failure.");
-        error("%s\r\n", "func:'canReceive()' error: 'Message recieve failure.'");
-    }
-}
-
-void SensorNode::Reset() {
-    _leftTicks = 0;
-    _rightTicks = 0;
-    _leftRevolutions = 0;
-    _rightRevolutions = 0;
-    _can.reset();
+/*
+ * File: SensorNode/SensorNode.cpp
+ * Author: William Jessup Salisbury
+ * Company: Tufts Hybrid Racing Team
+ * Copyright: CC BY-NC-SA 3.0
+ * Date: 1/12/2012
+ */
+
+#include "mbed.h"
+#include "CANProtocol.h"
+#include "SensorNode.h"
+
+SensorNode::SensorNode() : _leftWheel(LW_PIN), _rightWheel(RW_PIN), _can(CAN_RX, CAN_TX), _console(USBTX, USBRX), _leftTicks(0), _rightTicks(0), _leftRevolutions(0), _rightRevolutions(0), _syncID(0)  {
+    /* InterruptIn initialization */
+    _leftWheel.mode(PullUp);
+    _leftWheel.fall(this, &SensorNode::leftTick);
+    _rightWheel.mode(PullUp);
+    _rightWheel.fall(this, &SensorNode::rightTick);
+
+    /* CAN initialization */
+    _can.frequency(CAN_FREQUENCY);
+    _can.attach(this, &SensorNode::canReceive);
+
+    /* Ticker initialization */
+    //_statusTicker.attach(this, &SensorNode::canSend, tickerTimeout);
+
+    /* Hello, World! */
+    _console.printf("%s\r\n", "SensorNode instantiated");
+}
+
+SensorNode::~SensorNode() {
+    _statusTicker.detach();
+}
+
+void SensorNode::leftTick() {
+    if ( (++_leftTicks % ticksPerRevolution) == 0 ) {
+        _leftTicks = 0;
+        ++_leftRevolutions;
+    }
+}
+
+void SensorNode::rightTick() {
+    if ( (++_rightTicks % ticksPerRevolution) == 0 ) {
+        _rightTicks = 0;
+        ++_rightRevolutions;
+    }
+}
+
+void SensorNode::canSend() {
+    CANMessage msg;
+    msg.id = CAN_STATUS;
+    msg.len = 8;
+    msg.data[0] = _syncID;
+    msg.data[1] = 0xE;
+    msg.data[2] = 0xA;
+    msg.data[3] = 0xD;
+    msg.data[4] = 0xB;
+    msg.data[5] = 0xE;
+    msg.data[6] = 0xE;
+    msg.data[7] = 0xF;
+    if (_can.write(msg)) {
+        _console.printf("%s\r\n", "Message sent.");
+    } else {
+        _console.printf("%s\r\n", "Message send failure.");
+    }
+}
+
+void SensorNode::canReceive() {
+    CANMessage msg;
+
+    if (_can.read(msg)) {
+        switch (msg.id) {
+            case CAN_RESET:
+                _console.printf("%s\r\n", "CAN_RESET Message received.");
+                Reset();
+                break;
+
+            case CAN_SYNC:
+                _console.printf("%s\r\n", "CAN_SYNC Message received.");
+                _syncID = msg.data[0];
+                canSend();
+                break;
+
+            default:
+                _console.printf("%s\r\n", "Message decode failure.");
+                break;
+        }
+    } else {
+        _console.printf("%s\r\n", "Message recieve failure.");
+    }
+}
+
+void SensorNode::Reset() {
+    _leftTicks = 0;
+    _rightTicks = 0;
+    _leftRevolutions = 0;
+    _rightRevolutions = 0;
+    _can.reset();
 }
\ No newline at end of file
--- a/SensorNode.h	Thu Jan 12 20:44:36 2012 +0000
+++ b/SensorNode.h	Sun Apr 15 00:12:28 2012 +0000
@@ -11,8 +11,8 @@
 
 #include "mbed.h"
 
-const PinName CAN_RX = p9;
-const PinName CAN_TX = p10;
+const PinName CAN_RX = p30;
+const PinName CAN_TX = p29;
 const PinName LW_PIN = p11;
 const PinName RW_PIN = p12;
 
--- a/main.cpp	Thu Jan 12 20:44:36 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-/*
- * File: SensorNode/main.cpp
- * Author: William Jessup Salisbury
- * Company: Tufts Hybrid Racing Team
- * Copyright: CC BY-NC-SA 3.0
- * Date: 1/12/2012
- */
-
-#include "mbed.h"
-#include "SensorNode.h"
-
-SensorNode sn;
-
-int main() {
-    while (true)
-        __WFI();
-}
\ No newline at end of file
--- a/mbed.bld	Thu Jan 12 20:44:36 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/5364839841bd