2014 sift / Mbed 2 deprecated TVDctrller2017_brdRev1_PandA

Dependencies:   mbed

Fork of TVDctrller2017_brdRev1_ver6 by 2014 sift

main.cpp

Committer:
sift
Date:
2016-08-09
Revision:
13:6dc51981f391
Parent:
12:ae291fa7239c
Child:
14:7cc98e159c6e

File content as of revision 13:6dc51981f391:

#include "mbed.h"
#include "TVDCTRL.h"
#include "Steering.h"
#include "MCP4922.h"

Serial pc(USBTX, USBRX); // tx, rx

////////////////////////////////////////
//IO宣言
SPI spi(p5,p6,p7);
MCP4922 mcp(p5,p7,p8);  // MOSI, SCLK, CS
Serial com2(p9, p10);   //xbeeとかデバッグ用
DigitalOut cs(p11);
//12
//13
//14
InterruptIn rightMotorPulse(p15);
InterruptIn leftMotorPulse(p16);
AnalogIn brake(p17);
AnalogOut ana(p18);
AnalogIn apsS(p19);     //"S"econdary
AnalogIn apsP(p20);     //"P"rimary
DigitalOut indicatorLed(p21);
DigitalOut shutDown(p22);
DigitalOut MotorPulse[] = {p23, p24};
DigitalIn RTDSW(p25);
DigitalIn SDState(p26);
Serial com1(p28, p27);  //インパネとの通信に使用するかも知れなくもないかもしれない

DigitalOut LED[] = {LED1, LED2, LED3, LED4};
//DigitalOut watchDog();
CAN can(p30, p29);

#define indicateSystem(x)       (indicatorLed.write(x))
#define shutdownSystem(void)    (shutDown.write(0))
#define bootSystem(void)        (shutDown.write(1))
#define isPressedRTD(void)      (!RTDSW.read())
#define isShutdownSystem(void)  (SDState.read())

Timer timer;

void initIO(void)
{
    indicatorLed = 0;
    shutDown = 0;
    LED[0] = LED[1] = LED[2] = LED[3] = 0;

    RTDSW.mode(PullUp);
    SDState.mode(PullUp);

    indicateSystem(1);
    bootSystem();
}

int main(void)
{
    pc.baud(115200);

    printf("\r\nVersion:TVDcontrol_BETA...start!!!!!\r\n");

    initIO();       //IOポート初期化

    initTVD();

    initSteering();

    timer.start();

    wait(1);

    float time;

    struct errCounter_t eCounter= {0,0,0,0,0,0,0,0};
    while(1) {
        getCurrentErrCount(&eCounter);

        timer.reset();

        driveTVD();

        //printf("%f\n\r", 45.0/0xFFFF * calcRequestTorque());

        //printf("%2.2f\t%3.2f\t%1.2f\r\n", 45.0f / 0xffff * calcRequestTorque(), getVelocity(), getSteerAngle());
        //printf("%1.6f\r\n", time);
        //printf("%d\r\n", eCounter.brakeOverRide);
        time = timer.read();
        while(timer.read_ms() < 10);

        //printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t\r\n", eCounter.apsUnderVolt, eCounter.apsExceedVolt, eCounter.apsErrorTolerance, eCounter.apsStick, eCounter.brakeUnderVolt, eCounter.brakeExceedVolt, eCounter.brakeFuzzyVolt, eCounter.brakeOverRide);
        //printf("apsP:%f, apsS:%f, brake:%f\r", 3.3f/65535 * getRawSensor(APS_PRIMARY), 3.3f/65535 * getRawSensor(APS_SECONDARY), 3.3f/65535 * getRawSensor(BRAKE));

        //wait(0.05);
    }
}