New quadrupod variant

Dependencies:   ArthropodIK MMA8451Q MODSERIAL TSI TextLCD mbed-rtos mbed

Fork of Quadrapod by Ian Krase

main.cpp

Committer:
ikrase
Date:
2015-07-07
Revision:
10:11176c9c42fc
Parent:
7:68e488d28f67
Child:
11:2cf1f6ff9656

File content as of revision 10:11176c9c42fc:

#include "mbed.h"
#include "rtos.h"
#include "MODSERIAL.h"
#include <vector>
#include "mbed_rpc.h"

#include "quadrapod_defs.h" //Includes pins and stuff
#include "ArthropodIK.h"    // IK solver based on Oscar Liang. 
#include "PolyServo.h"

/**************************************************************************
              This is the Quadrupod control software.  
***************************************************************************/


MODSERIAL pc(USBTX, USBRX);

DigitalOut led_green(LED_GREEN);
DigitalOut led_red(LED_RED);
DigitalOut led_blue(LED_BLUE);

PwmOut LCD_red(LED_BL_RED);
PwmOut LCD_grn(LED_BL_GRN);
PwmOut LCD_blu(LED_BL_BLU);

float red_intensity, green_intensity, blue_intensity; 
RPCVariable<float> rpc_bl_red(&red_intensity, "red_lvl");
RPCVariable<float> rpc_bl_grn(&green_intensity, "green_lvl");
RPCVariable<float> rpc_bl_blu(&blue_intensity, "blue_lvl");

ArthropodSolver IKsolver();

std::vector<DigitalOut * > digivec;

void led_fade_thread(void const *args) {
  // Note that this function doesn't terminate, which is fine since it runs in
  // a thread.
  while (1) {
    // Since the internal LED is active low, inert the duty cycle.
    led_blue.write(1 - 0);
    Thread::wait(250);
    led_blue.write(1 - 0.25);
    Thread::wait(250);
    led_blue.write(1 - 0.5);
    Thread::wait(250);
    led_blue.write(1 - 0.75);
    Thread::wait(250);
    
  }
}

void led_blink_periodic(void const *args) {
  // Toggle the red LED when this function is called.
  led_red = !led_red;
}

int main() {
  // It's always nice to know what version is deployed.
  //serial.printf("Built " __DATE__ " " __TIME__ "\r\n");
  
  // Quick blink on startup.
  led_green = 0;  // Note that the internal LED is active low.
  wait(0.25);
  led_green = 1;
  wait(0.25);
  
  // Mandatory "Hello, world!".
  serial.printf("Hello, world!\r\n");

  // Start a thread running led_fade_thread().
  Thread ledFadeThread(led_fade_thread);
  
  // Set a timer to periodically call led_blink_periodic().
  RtosTimer ledBlinkTimer(led_blink_periodic);
  ledBlinkTimer.start(1000);
  char buf[256], outbuf[256];

  // Work is done in the threads, so main() can sleep.
    while (1) {
        Thread::wait(100);
        LCD_red = red_intensity;
        LCD_grn = green_intensity;
        LCD_blu = blue_intensity;   
        
        
        pc.gets(buf, 256);
        //Call the static call method on the RPC class
        RPC::call(buf, outbuf); 
        pc.printf("%s\n", outbuf);
        
        
    }
  
  
  
  Thread::wait(osWaitForever);
}