Scanning LiDAR firmware for the Sprite project

Files at this revision

API Documentation at this revision

Comitter:
abraha2d
Date:
Sun Mar 24 20:25:43 2019 +0000
Commit message:
Initial boilerplate commit

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
config.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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
pindefs.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Sun Mar 24 20:25:43 2019 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.h	Sun Mar 24 20:25:43 2019 +0000
@@ -0,0 +1,10 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+// ESC PWM period (seconds)
+#define CONF_ESC_PERIOD         20e-3
+
+// ESC PWM pulsewidth (seconds)
+#define CONF_ESC_PULSEWIDTH     1748e-6
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 24 20:25:43 2019 +0000
@@ -0,0 +1,135 @@
+#include "mbed.h"
+#include "pindefs.h"
+#include "config.h"
+
+
+
+/**
+ * Devices
+ */
+
+// Encoder
+InterruptIn enc_idx     (PIN_ENC_IDX);
+InterruptIn enc_cha     (PIN_ENC_CHA);
+
+// ESC
+PwmOut      esc_pwm     (PIN_ESC_PWM);
+
+// Rangefinder
+InterruptIn rgf_sync    (PIN_RGF_SYNC);
+Serial      rgf_serial  (PIN_RGF_RXD, PIN_RGF_TXD);
+
+// LEDs
+DigitalOut  led1        (LED1);
+DigitalOut  led2        (LED2);
+DigitalOut  led3        (LED3);
+DigitalOut  led4        (LED4);
+
+
+
+/**
+ * Global variables
+ */
+
+// Rangefinder data acquisition state
+int rgf_state = 0;
+
+// Encoder data acquisition state
+int enc_state = 0;
+
+
+
+/**
+ * Interrupt service routines
+ */
+
+// Encoder index pulse
+void isr_enc_idx()
+{
+    led2 = !led2;
+}
+
+// Encoder channel A pulse
+void isr_enc_cha()
+{
+    led3 = !led3;
+}
+
+// Rangefinder sync pulse
+void isr_rgf_sync()
+{
+    led4 = !led4;
+}
+
+
+
+/**
+ * Threads
+ */
+
+// Blink thread
+Thread blink;
+void thread_blink()
+{
+    for(;;) {
+        led1 = !led1;
+        wait(1);
+    }
+}
+
+
+
+/**
+ * Setup functions
+ */
+
+// Encoder
+void setup_enc()
+{
+    enc_idx.rise(&isr_enc_idx);
+    enc_cha.rise(&isr_enc_cha);
+}
+
+// ESC
+void setup_esc()
+{
+    esc_pwm.period(CONF_ESC_PERIOD);            // 20 ms
+    esc_pwm.pulsewidth(CONF_ESC_PULSEWIDTH);    // 1748 µs
+}
+
+// Rangefinder
+void setup_rgf()
+{
+    rgf_sync.fall(&isr_rgf_sync);
+}
+
+// Threads
+void setup_threads()
+{
+    blink.start(thread_blink);
+}
+
+
+
+/**
+ * Main
+ */
+
+int main()
+{
+    /* Setup */
+
+    setup_enc();
+    setup_esc();
+    setup_rgf();
+    setup_threads();
+
+    /* Loop */
+
+    for (;;) {
+
+        wait(0);
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sun Mar 24 20:25:43 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#51d55508e8400b60af467005646c4e2164738d48
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pindefs.h	Sun Mar 24 20:25:43 2019 +0000
@@ -0,0 +1,18 @@
+#ifndef PINDEFS_H
+#define PINDEFS_H
+
+// Encoder index, channel A
+#define PIN_ENC_IDX     p23
+#define PIN_ENC_CHA     p24
+
+// ESC PWM
+#define PIN_ESC_PWM     p25
+
+// Rangefinder synchronization
+#define PIN_RGF_SYNC    p26
+
+// Rangefinder serial
+#define PIN_RGF_TXD     p27
+#define PIN_RGF_RXD     p28
+
+#endif
\ No newline at end of file