New quadrupod variant
Dependencies: ArthropodIK MMA8451Q MODSERIAL TSI TextLCD mbed-rtos mbed
Fork of Quadrapod by
main.cpp@10:11176c9c42fc, 2015-07-07 (annotated)
- Committer:
- ikrase
- Date:
- Tue Jul 07 07:01:53 2015 +0000
- Revision:
- 10:11176c9c42fc
- Parent:
- 7:68e488d28f67
- Child:
- 11:2cf1f6ff9656
Probably EOL. .This got too complicated too fast.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikrase | 0:838403674a8f | 1 | #include "mbed.h" |
ikrase | 0:838403674a8f | 2 | #include "rtos.h" |
ikrase | 0:838403674a8f | 3 | #include "MODSERIAL.h" |
ikrase | 7:68e488d28f67 | 4 | #include <vector> |
ikrase | 10:11176c9c42fc | 5 | #include "mbed_rpc.h" |
ikrase | 0:838403674a8f | 6 | |
ikrase | 0:838403674a8f | 7 | #include "quadrapod_defs.h" //Includes pins and stuff |
ikrase | 2:1f7ee9f3276b | 8 | #include "ArthropodIK.h" // IK solver based on Oscar Liang. |
ikrase | 7:68e488d28f67 | 9 | #include "PolyServo.h" |
ikrase | 0:838403674a8f | 10 | |
ikrase | 0:838403674a8f | 11 | /************************************************************************** |
ikrase | 0:838403674a8f | 12 | This is the Quadrupod control software. |
ikrase | 0:838403674a8f | 13 | ***************************************************************************/ |
ikrase | 0:838403674a8f | 14 | |
ikrase | 0:838403674a8f | 15 | |
ikrase | 10:11176c9c42fc | 16 | MODSERIAL pc(USBTX, USBRX); |
ikrase | 0:838403674a8f | 17 | |
ikrase | 0:838403674a8f | 18 | DigitalOut led_green(LED_GREEN); |
ikrase | 0:838403674a8f | 19 | DigitalOut led_red(LED_RED); |
ikrase | 10:11176c9c42fc | 20 | DigitalOut led_blue(LED_BLUE); |
ikrase | 10:11176c9c42fc | 21 | |
ikrase | 10:11176c9c42fc | 22 | PwmOut LCD_red(LED_BL_RED); |
ikrase | 10:11176c9c42fc | 23 | PwmOut LCD_grn(LED_BL_GRN); |
ikrase | 10:11176c9c42fc | 24 | PwmOut LCD_blu(LED_BL_BLU); |
ikrase | 10:11176c9c42fc | 25 | |
ikrase | 10:11176c9c42fc | 26 | float red_intensity, green_intensity, blue_intensity; |
ikrase | 10:11176c9c42fc | 27 | RPCVariable<float> rpc_bl_red(&red_intensity, "red_lvl"); |
ikrase | 10:11176c9c42fc | 28 | RPCVariable<float> rpc_bl_grn(&green_intensity, "green_lvl"); |
ikrase | 10:11176c9c42fc | 29 | RPCVariable<float> rpc_bl_blu(&blue_intensity, "blue_lvl"); |
ikrase | 0:838403674a8f | 30 | |
ikrase | 3:9916f013d978 | 31 | ArthropodSolver IKsolver(); |
ikrase | 3:9916f013d978 | 32 | |
ikrase | 7:68e488d28f67 | 33 | std::vector<DigitalOut * > digivec; |
ikrase | 7:68e488d28f67 | 34 | |
ikrase | 0:838403674a8f | 35 | void led_fade_thread(void const *args) { |
ikrase | 0:838403674a8f | 36 | // Note that this function doesn't terminate, which is fine since it runs in |
ikrase | 0:838403674a8f | 37 | // a thread. |
ikrase | 0:838403674a8f | 38 | while (1) { |
ikrase | 0:838403674a8f | 39 | // Since the internal LED is active low, inert the duty cycle. |
ikrase | 0:838403674a8f | 40 | led_blue.write(1 - 0); |
ikrase | 0:838403674a8f | 41 | Thread::wait(250); |
ikrase | 0:838403674a8f | 42 | led_blue.write(1 - 0.25); |
ikrase | 0:838403674a8f | 43 | Thread::wait(250); |
ikrase | 0:838403674a8f | 44 | led_blue.write(1 - 0.5); |
ikrase | 0:838403674a8f | 45 | Thread::wait(250); |
ikrase | 0:838403674a8f | 46 | led_blue.write(1 - 0.75); |
ikrase | 0:838403674a8f | 47 | Thread::wait(250); |
ikrase | 7:68e488d28f67 | 48 | |
ikrase | 0:838403674a8f | 49 | } |
ikrase | 0:838403674a8f | 50 | } |
ikrase | 0:838403674a8f | 51 | |
ikrase | 0:838403674a8f | 52 | void led_blink_periodic(void const *args) { |
ikrase | 0:838403674a8f | 53 | // Toggle the red LED when this function is called. |
ikrase | 0:838403674a8f | 54 | led_red = !led_red; |
ikrase | 0:838403674a8f | 55 | } |
ikrase | 0:838403674a8f | 56 | |
ikrase | 0:838403674a8f | 57 | int main() { |
ikrase | 0:838403674a8f | 58 | // It's always nice to know what version is deployed. |
ikrase | 10:11176c9c42fc | 59 | //serial.printf("Built " __DATE__ " " __TIME__ "\r\n"); |
ikrase | 0:838403674a8f | 60 | |
ikrase | 0:838403674a8f | 61 | // Quick blink on startup. |
ikrase | 0:838403674a8f | 62 | led_green = 0; // Note that the internal LED is active low. |
ikrase | 0:838403674a8f | 63 | wait(0.25); |
ikrase | 0:838403674a8f | 64 | led_green = 1; |
ikrase | 0:838403674a8f | 65 | wait(0.25); |
ikrase | 0:838403674a8f | 66 | |
ikrase | 0:838403674a8f | 67 | // Mandatory "Hello, world!". |
ikrase | 0:838403674a8f | 68 | serial.printf("Hello, world!\r\n"); |
ikrase | 0:838403674a8f | 69 | |
ikrase | 0:838403674a8f | 70 | // Start a thread running led_fade_thread(). |
ikrase | 0:838403674a8f | 71 | Thread ledFadeThread(led_fade_thread); |
ikrase | 0:838403674a8f | 72 | |
ikrase | 0:838403674a8f | 73 | // Set a timer to periodically call led_blink_periodic(). |
ikrase | 0:838403674a8f | 74 | RtosTimer ledBlinkTimer(led_blink_periodic); |
ikrase | 0:838403674a8f | 75 | ledBlinkTimer.start(1000); |
ikrase | 10:11176c9c42fc | 76 | char buf[256], outbuf[256]; |
ikrase | 0:838403674a8f | 77 | |
ikrase | 0:838403674a8f | 78 | // Work is done in the threads, so main() can sleep. |
ikrase | 10:11176c9c42fc | 79 | while (1) { |
ikrase | 10:11176c9c42fc | 80 | Thread::wait(100); |
ikrase | 10:11176c9c42fc | 81 | LCD_red = red_intensity; |
ikrase | 10:11176c9c42fc | 82 | LCD_grn = green_intensity; |
ikrase | 10:11176c9c42fc | 83 | LCD_blu = blue_intensity; |
ikrase | 10:11176c9c42fc | 84 | |
ikrase | 10:11176c9c42fc | 85 | |
ikrase | 10:11176c9c42fc | 86 | pc.gets(buf, 256); |
ikrase | 10:11176c9c42fc | 87 | //Call the static call method on the RPC class |
ikrase | 10:11176c9c42fc | 88 | RPC::call(buf, outbuf); |
ikrase | 10:11176c9c42fc | 89 | pc.printf("%s\n", outbuf); |
ikrase | 10:11176c9c42fc | 90 | |
ikrase | 10:11176c9c42fc | 91 | |
ikrase | 10:11176c9c42fc | 92 | } |
ikrase | 10:11176c9c42fc | 93 | |
ikrase | 10:11176c9c42fc | 94 | |
ikrase | 10:11176c9c42fc | 95 | |
ikrase | 0:838403674a8f | 96 | Thread::wait(osWaitForever); |
ikrase | 0:838403674a8f | 97 | } |