Juggler Position Control Parsing

Dependencies:   MODSERIAL mbed Servo

Fork of juggler_mbed_position_control by Robert Katzschmann

main.cpp

Committer:
rkk
Date:
2017-01-09
Revision:
0:1b69f8402884
Child:
1:153ce28ac5ed

File content as of revision 0:1b69f8402884:

#include "mbed.h"
#include "MODSERIAL/MODSERIAL.h"
#include "SerialComm/SerialComm.h"

#define NUM_FLOATS 10


MODSERIAL pcSerial(USBTX, USBRX);

// Initialize a pins t//o perform analog and digital output fucntions
AnalogOut  aout(p18);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
//DigitalOut led3(LED3);

//Serial pc(USBTX, USBRX);
float valueFloats[NUM_FLOATS];
float voltage;

SerialComm serialComm(&pcSerial);




int main(void)
{
    pcSerial.printf("Start!\n");
    //pcSerial.baud(19200);

    while(true) {
        if(serialComm.checkIfNewMessage()) {
            valueFloats[0] = serialComm.getFloat();//valueFloats, NUM_FLOATS);
            led2 = !led2;
            //pcSerial.printf("Result: ");
            //pcSerial.printf("%f", valueFloats[0]);

            // change the voltage on the digital output pin by 0.1 * VCC
            //  and print what the measured voltage should be (assuming VCC = 3.3v)
            //for (float i = 0.0f; i < 1.0f; i += 0.1f) {
            voltage = (abs(valueFloats[0]) > 3.3f) ? 3.3f : abs(valueFloats[0]);
            aout = voltage / 3.3f;
            //pc.printf("aout = %1.2f volts\n", aout.read() * 3.3f);
            // turn on the led if the voltage is greater than 0.5f * VCC
            led1 = (aout > 0.5f) ? 1 : 0; // voltage larger than 0.5*3.3
            //led3 = !led3;

        }
        wait(1.0f);
    }
}