Anteater Electric Racing at UC Irvine

Embedded systems development of an Formula SAE Electric Racecar at the University of California, Irvine.

IntermediateWork in progress739
Anteater Electric Racing at UC Irvine

Things used in this project

Hardware components

Texas Instruments MSP430G2ET
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×4

Software apps and online services

Code Composer Studio
Texas Instruments Code Composer Studio

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Circuit Diagram

Code

Faults.h

C Header File
Header file for fault checking code
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/


//returns 1 if fault, 0 if no fault. (checks acc pedal transfer functions)
int APPS_Fault(int,int);

//returns 1 if BSE fault, 0 if no fault (checks that acc is not depressed when brake is depressed >10%)
int BSE_Fault(int,int,int);

main.c

C/C++
Main file for program flow and torque vectoring code
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/

#include <ADC.h>
#include <Faults.h>
#include <PWM.h>
#include <msp430g2553.h>
#include <stdint.h>


int steeringval;
int accval;
int acc2New;

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
    BCSCTL1 = CALBC1_16MHZ; // Set range
    DCOCTL = CALDCO_16MHZ;
    init_ADC();		//initiate ADC 
    init_PWM();		//initiate PWM
    while (1) {
		read_ADC();		//read input from potentiometers
		
        if(APPS_Fault(acc1Input,acc2Input) || BSE_Fault(brakeInput,acc1Input,acc2Input)){
           AcceleratorL = 0;		//Set throttle signals to 0 if fault occurs
           AcceleratorR = 0;
           setThrottleValue(AcceleratorL,AcceleratorR);
        }
        else {
			int accel = acc1Input;
			float B = 0.4; // offset of curve for torque vectoring
			float A = 0.6/(72); // slope of curve for left  turn torque vectoring
			float D = 0.6/(77); // slope of curve for right turn torque vectoring
			steeringval = steeringInput; //steering potentiometer value
			//TORQUE VECTORING BASIC ALGORITHM
			if (steeringval < 373 && steeringval > 84) { //left turn calibrated for 20% margine b4 turn engaging
				AcceleratorR = accel *( A*((512-steeringval) - 84) + B)*0.605; //calibrated so it is 40% at full turn
				AcceleratorL = accel*0.605;
            }
			else if (steeringval < 84){
				AcceleratorR = 1023*0.605;
				AcceleratorL = accel*0.605;
			}
			else if (steeringval > 534 && steeringval < 842) {                 //right turn calibrated for 20% margine
				AcceleratorR = accel*0.605;
				AcceleratorL = accel *(D *(842-(1023-steeringval)) + B)*0.605;  //calibrated so it is 40% at full turn

			}
			else if (steeringval > 842){
				AcceleratorR = accel*0.605;
				AcceleratorL = 1023*0.605;
			}
			else { //on center steering.
				AcceleratorR = accel*0.605;
				AcceleratorL = accel*0.605;
			}

			setThrottleValue(AcceleratorL,AcceleratorR);		//Sends accelerator signals for PWM output
		}
    }
}

PWM.c

C/C++
Pulse width modulation initialization and duty cycle setting code
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/

#include <msp430g2553.h>
#include "PWM.h"

void init_PWM(){
    P2DIR |= BIT1;
    P2SEL |= BIT1;
    P1DIR |= BIT6;
    P1SEL |= BIT6;

    TA1CCR0 |= 624;  //625 is the period for 1.6kHz so value is 0-624
    TA1CCTL1 |= OUTMOD_7;
    TA1CCR1 |= 0;   //initialize PWM at 0 duty cycle
    TA1CTL |= TASSEL_2 + MC_1;

    TA0CCR0 = 624;	//625 is the period for 1.6kHz so value is 0-624
    TA0CCTL1 = OUTMOD_7;
    TA0CCR1 |= 0;	//initialize PWM at 0 duty cycle
    TA0CTL |= TASSEL_2 + MC_1;
}

void setThrottleValue(int accL, int accR){
    if(accL < 5){
        accL = 5;
    }
    else if(accL > 1015){
        accL = 1015;
    }
    if(accR < 5){
        accR = 5;
    }
    else if(accR > 1015){
        accR = 1015;
    }
    TA1CCR1 = accL;
    TA0CCR1 = accR;
  //      __bis_SR_register(LPM0_bits);
}

PWM.h

C Header File
Header file for PWM.c
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/

int AcceleratorL;  //Left motor duty cycle
int AcceleratorR;  //Right motor duty cycle

__interrupt void Timer_A0_CC0(void);
__interrupt void Timer_A1_CC1(void);

void init_PWM();

void setThrottleValue(int , int );

ADC.c

C/C++
Functions for ADC initialization and storing values
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/

#include <ADC.h>
#include <msp430g2553.h>

// ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
#else
#error Compiler not supported!
#endif
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}

void init_ADC(){
    ADC10CTL1 = INCH_3 + CONSEQ_1; //Channel 5 down to 0  and sets up single channel conversion
    ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
    ADC10DTC1 = 4;
    ADC10AE0 = BIT3 + BIT2 + BIT1 + BIT0;   //enables analog on pin 1.0, 1.3, 1.4, and 1.5
}

void read_ADC(){
    ADC10CTL0 &= ~ENC;
    while(ADC10CTL1 & BUSY);
    ADC10SA = (unsigned int)adc;
    ADC10CTL0 |= ENC + ADC10SC;
    __bis_SR_register(CPUOFF + GIE);

    steeringInput = adc[0];
    brakeInput = adc[1];
    acc1Input = adc[2];
    acc2Input = adc[3];
}

ADC.h

C Header File
Header file for ADC.c
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/

unsigned int adc[4];
int acc1Input;
int acc2Input;
int brakeInput;
int steeringInput;


__interrupt void ADC10_ISR(void);

void init_ADC();
void read_ADC();

Faults.c

C/C++
Functions to check for faults
/*
Component: Driver Input Module
Engineer: Lucas Juttner
Company: UC Irvine Anteater Electric Racing
Date: February 12, 2019
Description: The Driver Input Module (DIM) is a Texas Instruments MSP430G2ET (implemented with a G2553 integrated circuit) 
micro-controller with the requirements of handling driver input of Lithium, UC Irvines 2019 FSAE Electric Racecar 
competing in Lincoln, Nebraska. 
*/

#include <Faults.h>
#include <stdint.h>

int BSE_flag = 0;
//returns 1 if fault, 0 if no fault. (checks acc pedal transfer functions)
int APPS_Fault(int acc1, int acc2){
    //102 is 10% of 1023 which is the max value for ADC inputs
    //if acc1 or 2 is <10 then there is a disconnect on the line since it is pulled down.
    //if apps flag has been already triggered but fault is still occurring, do nothing
    acc2 = 1023 - acc2;		//Accelerator 2 potentiometer has a negative transfer function to Accelerator 1
    if((abs(acc1-acc2) > 102) || (acc1 < 10) || (acc2 < 10)) {
        return 1;
    }
    //if there is no fault occurring, disable APPS flag if it is triggered and continue execution.
    else {
        return 0;
    }
}

//returns 1 if BSE fault, 0 if no fault (checks that brake is not depressed when acc is depressed >25%)
int BSE_Fault(int brakeAngle, int acc1, int acc2){
    acc2 = 1023 - acc2;		//Accelerator 2 potentiometer has a negative transfer function to Accelerator 1
    if((BSE_flag) && (acc1 > 51 || acc2 > 51)) { //51 is 5% of 1023
        return 1;
    }
    if((acc1 > 256 || acc2 > 256) && brakeAngle > 542){ //256 is 25% of 1023      542 is 53% of 5V where 2.67V is "hard press" of brakes
        BSE_flag = 1;
        return 1;
    }
    else if ((BSE_flag) && (acc1 < 51 && acc2 < 51)){ //51 is 5% of 1023  if flag is already set, flag will clear when APPS values are less than 5%
        BSE_flag = 0;
        return 0;
    }
    return 0;

}

Credits

Michael R. Honar

Michael R. Honar

2 projects • 9 followers
Lucas Juttner

Lucas Juttner

2 projects • 8 followers
Rieli Tjan

Rieli Tjan

1 project • 6 followers
Saipraneeth Muktevi

Saipraneeth Muktevi

1 project • 5 followers
Tom

Tom

1 project • 7 followers
Michael Barbosa-Aguayo

Michael Barbosa-Aguayo

0 projects • 4 followers

Comments