2018 revision to classic DataBus AVC code.

Dependencies:   LSM303DLM Servo SerialGraphicLCD L3G4200D IncrementalEncoder SimpleShell

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Wed Dec 12 18:21:57 2018 +0000
Parent:
13:5566df1250f1
Child:
15:35c40765f7c3
Commit message:
Added encoder read to Updater, added documentation, added shell cmd to read encoder

Changed in this revision

IncrementalEncoder.lib Show annotated file Show diff for this revision Revisions of this file
SimpleShell.lib Show annotated file Show diff for this revision Revisions of this file
Updater.cpp Show annotated file Show diff for this revision Revisions of this file
Updater.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
pinouts.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IncrementalEncoder.lib	Wed Dec 12 18:21:57 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/shimniok/code/IncrementalEncoder/#dea4a931b267
--- a/SimpleShell.lib	Wed Dec 12 17:38:02 2018 +0000
+++ b/SimpleShell.lib	Wed Dec 12 18:21:57 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/shimniok/code/SimpleShell/#8f486f4d29d3
+https://os.mbed.com/users/shimniok/code/SimpleShell/#b58450c94d32
--- a/Updater.cpp	Wed Dec 12 17:38:02 2018 +0000
+++ b/Updater.cpp	Wed Dec 12 18:21:57 2018 +0000
@@ -1,17 +1,24 @@
 #include "Updater.h"
-
+#include "pinouts.h"
+#include "IncrementalEncoder.h"
 
 void Updater::gyro(int g[3], float& dt) 
 {
     for (int i=0; i < 3; i++) {
         g[i] = _gyro[i];
     }
-    
     dt = _dt;
     
     return;
 }
 
+int Updater::encoder()
+{
+    int result=_ecount;
+    _ecount = 0;
+    
+    return result;    
+}
 
 Updater *Updater::instance() 
 {
@@ -41,7 +48,8 @@
 void Updater::update()
 {
     static DigitalOut led2(LED2);
-    static L3G4200D gyro(p9, p10); // TODO parameterize
+    static L3G4200D gyro(I2CSDA, I2CSCL); // TODO parameterize
+    static IncrementalEncoder enc(ALEFT);
 
     // Compute dt
     thisTime = t->read_us();
@@ -49,6 +57,8 @@
     lastTime = thisTime;
 
     // Read encoders
+    _ecount += enc.read();
+    
     // Read gyro
     gyro.read(_gyro);
     
--- a/Updater.h	Wed Dec 12 17:38:02 2018 +0000
+++ b/Updater.h	Wed Dec 12 18:21:57 2018 +0000
@@ -6,15 +6,36 @@
 
 class Updater: private mbed::NonCopyable<Updater> {
 public:
+    /** Start the updater running - cannot be exited!
+     * @param interval_ms is the interval in ms between calls to update()
+     * @note Makes use of RTOS EventQueue and Event.
+     */
     void start(int interval_ms);
+
+    /// Return singleton instance
     static Updater *instance();
+    
+    /** Get gyro values
+     * @return g array of x, y, and z gyro values
+     * @return dt time since data last updated
+     */
     void gyro(int g[3], float& dt);
-      
+    
+    /** Get encoder count
+     * @return encoder count since last call
+     */
+    int encoder();
+
 private:
-    Updater() {} // parameterize
-    Timer *t;
-    void update();
-    int _gyro[3];
+    /// Basic constructor (singleton)
+    Updater() {}
+    
+    /// Update all sensors
+    void update(); 
+    
+    Timer *t; // timer used to measure dt
+    int _gyro[3]; // gyro raw
+    int _ecount; // encoder count
     float _dt;
     int thisTime;
     int lastTime;
--- a/main.cpp	Wed Dec 12 17:38:02 2018 +0000
+++ b/main.cpp	Wed Dec 12 18:21:57 2018 +0000
@@ -41,6 +41,13 @@
     printf("Gyro: %d, %d, %d - dt: %f\n", g[0], g[1], g[2], dt);
 }
 
+void read_enc()
+{
+    Updater *u = Updater::instance();
+    
+    printf("Encoder: %d\n", u->encoder());
+}
+
 void reset()
 {
     NVIC_SystemReset();
@@ -84,6 +91,7 @@
     printf("Starting shell...\n");
     sh.attach(test, "test");
     sh.attach(read_gyro, "gyro");
+    sh.attach(read_enc, "enc");
     sh.attach(reset, "reset");
     thread.start(callback(&sh, &SimpleShell::run));
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pinouts.h	Wed Dec 12 18:21:57 2018 +0000
@@ -0,0 +1,52 @@
+/// Contains the pinouts for various devices
+
+#ifndef BOARDS_H_
+#define BOARDS_H_
+
+#include "mbed.h"
+
+/** RoverBaseboard R0.5 */
+#define I2CSDA      p9
+#define I2CSCL      p10
+#define UART0TX     USBTX /** mbed */
+#define UART0RX     USBRX /** mbed */
+#define UART1TX     p13
+#define UART1RX     p14
+#define UART2TX     p28
+#define UART2RX     p27
+#define UART3TX     p17
+#define UART3RX     p18
+#define THROTTLE    p22
+#define STEERING    p21
+#define ENCALEFT    p30
+#define ALEFT       ENCALEFT
+#define ENCARIGHT   p29
+#define ARIGHT      ENCARIGHT
+#define ENCBLEFT    /** unavailable for mbed */
+#define BLEFT       ENCBLEFT
+#define ENCBRIGHT   /** unavailable for mbed */
+#define BRIGHT      ENCBRIGHT
+// REV 0.5
+#define _D0         p11
+#define _D1         p12
+#define _D2         /** unavailable for mbed */
+#define _D7         /** unavailable for mbed */
+#define _D8         /** unavailable for mbed */
+#define _D9         /** unavailable for mbed */
+#define _P1         p26
+#define _P2         p25
+#define _A0         p15
+#define _A1         p16
+#define _A2         p19
+#define _A3         p20
+// REV 0.6
+#define IO0         p11
+#define IO1         p12
+#define PW0         p25
+#define PW1         p26
+#define AN0         p15
+#define AN1         p16
+#define AN2         p19
+#define AN3         p20
+
+#endif /* BOARDS_H_ */
\ No newline at end of file