Corrected header file include guards.

Dependencies:   FiniteStateMachine HipControl Knee LinearBlend1 LocalFileSystem_Read dataComm hapticFeedback initExoVars mbed Blend_Generator Brad_poly_gait Gait_Generator MM_gait Encoders IMUdriver

Fork of Motion Control by HEL's Angels

main.cpp

Committer:
mzling
Date:
2015-04-27
Revision:
23:e0923403be2f
Parent:
22:357327fe25af
Child:
24:2e56d3bebb24

File content as of revision 23:e0923403be2f:

/**************************************
This is the main file for the "RyanEXO" control software.
This sets up the main control loop that operates at a 1kHz frequency
and controls the flow of the rest of the software

The configuration for the exo system that this software runs:
amplifiers: 2 Copley Controls 10A digital amplifiers
sensors: 2 Austria Microsystems 12 bit magnetic encoders, handled by encoders.h
motors: 2 maxon EC90 DC brushless motors, handled by HipMotorControl.h (called in FSM.h)
Knees: wrap spring clutch controlled by Firgelli PQ12P linear actuators, controlled in linearActuatorControl.h
**************************************/

#include "mbed.h"
#include "initExoVars.h"
#include "FSM.h"
#include "dataBedComm.h"
#include "dataComm.h"
short dataIn[7];
short dataOut[]={0xFF,30,31,0, 0, 0, 0, 0, 0xFE};
dataComm dc = dataComm();
Timer dbg;

///////////////////////////////////////////////////////////////////////////

// periodicFcns runs at the start of every control loop cycle
// It initiates communication with dataBed, checks for errors/safety, and starts the FSM

union float_to_short {
    float f;
    uint32_t u;
} q;
void periodicFcns()
{
    dbg.reset();
//    dataOut[1]=encoder_L.readRaw();
    float f1 = encoder_L.read_angle();
    float f2 = fsm.read_angle_y();
    //float f2 = -87.43423;
    short s1 = (short)(f1*91);
    short s2 = (short)(f2*91);
    dataOut[1] = s1;
    dataOut[2] = s2;
    pc.printf("first is %f %d\r\n", f1, s1);
    pc.printf("second is %f %d\r\n", f2, s2);
    //dataOut[3] = (short)f1;
    //dataOut[4] = (short)f2;
    //dataOut[5] = (short)f2;
    //pc.printf("%f\r\n", f1);
    //pc.printf("data1: %d\r\n", dataOut[1]);
    //pc.printf("%f\r\n", f2);
    //pc.printf("Size %d\r\n", sizeof dataOut[2]);
    //pc.printf("data2: %d\r\n", dataOut[2]);
    //for (int i = 2; i < 4; i++) {
      //  pc.printf("data%d is %x\r\n", i, dataOut[i]);
    //}
    //dataOut[2]=fsm.error();
    short* ptr=dataIn;
    ptr=sendData(dataOut, 9, dataIn);
    //for (int i = 0; i < 7; i++) {
        if (dataIn[1] != 0) {   
    pc.printf("UI: %d\r\n", dataIn[1]);
    }
    //}
    //pc.printf("\r\n");*/
    dc.process_write(dataIn+2, 7);
    //pc.printf("%d, %d, %d, %d,", dataIn[0], dataIn[1], dataIn[2], dataIn[3]);
    
    // Run state change/analysis in FSM
    int exoState=fsm.state(dataIn[1]);
    float temp=dbg.read_us();
    //pc.printf("%f\r\n",temp);
    
}

//Starts the Exo controlbed, and processes messages by repeatedly executing periodicFcns
int main()
{
    pc.printf("\r\nExoStart \r\n");
    initializeExoIOs();
    //pc.printf("Test\r\n"); // keep for debugging compile errors
    mbedLED1 = 1;
    pc.printf("Starting exo...\n\r");
    //If desired, a startup sound can be played. This function is defined in the DatabedCode, because it will command a sound to be played once it detects a heartbeat from ControlBed
    wait(2);
    dbg.start();
    Ticker doControl;
    dataBedSPI.format(16,0);
    doControl.attach(&periodicFcns, SAMPLE_TIME);

    while (1);
}