The Code Repository for the REV0 Steering Wheel.

Dependencies:   CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses

Fork of REVO_Updated_Steering by Penn Electric

Committer:
kiran_mbed
Date:
Mon Mar 23 19:36:37 2015 +0000
Revision:
42:701df58e923a
Parent:
36:8544a8900884
Removed Blocking of Start CAN Message.; Removed Sending of START Message bug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kiran_mbed 42:701df58e923a 1 /*
tmccurbin 36:8544a8900884 2 // FORMAT_CODE_START
tmccurbin 36:8544a8900884 3 // FORMAT_CODE_START
tmccurbin 36:8544a8900884 4 #include "Steering.h"
tmccurbin 36:8544a8900884 5
tmccurbin 36:8544a8900884 6 // Macro for printing to screen; Where y is the start poition of the text, and y2 is the start position of the variable
tmccurbin 36:8544a8900884 7 #define PUT2SCREEN(string, var, unit, x, y, y2) display.PutString(x, y, string); display.PutString(x, y2, var); display.PutString(x,y2+15,unit);
tmccurbin 36:8544a8900884 8
tmccurbin 36:8544a8900884 9 unsigned int x = 0;
tmccurbin 36:8544a8900884 10 unsigned int x_old = 0;
tmccurbin 36:8544a8900884 11 unsigned int x_new;
tmccurbin 36:8544a8900884 12 int diff = x_new-x_old;
tmccurbin 36:8544a8900884 13 int threshold = 1;
tmccurbin 36:8544a8900884 14 float y = 0.0;
tmccurbin 36:8544a8900884 15
tmccurbin 36:8544a8900884 16 void update_x(void const *args)
tmccurbin 36:8544a8900884 17 {
tmccurbin 36:8544a8900884 18 while (1) {
tmccurbin 36:8544a8900884 19 x++;
tmccurbin 36:8544a8900884 20 wait_ms(1); //I added this because the microcontroller was operating so fast that you couldn't read the numbers.
tmccurbin 36:8544a8900884 21 if (x >= 16000) {
tmccurbin 36:8544a8900884 22 x = 0;
tmccurbin 36:8544a8900884 23 }
tmccurbin 36:8544a8900884 24
tmccurbin 36:8544a8900884 25 x_new = x;
tmccurbin 36:8544a8900884 26 diff = x_new - x_old;
tmccurbin 36:8544a8900884 27 }
tmccurbin 36:8544a8900884 28 }
tmccurbin 36:8544a8900884 29
tmccurbin 36:8544a8900884 30 void update_y(void const *args)
tmccurbin 36:8544a8900884 31 {
tmccurbin 36:8544a8900884 32 while(1) {
tmccurbin 36:8544a8900884 33 y = y + 0.000001;
tmccurbin 36:8544a8900884 34 if (y >= 1.0) {
tmccurbin 36:8544a8900884 35 y = 0;
tmccurbin 36:8544a8900884 36
tmccurbin 36:8544a8900884 37 }
tmccurbin 36:8544a8900884 38 }
tmccurbin 36:8544a8900884 39
tmccurbin 36:8544a8900884 40 }
tmccurbin 36:8544a8900884 41
tmccurbin 36:8544a8900884 42 AnalogOut ledBar(p18);
tmccurbin 36:8544a8900884 43
tmccurbin 36:8544a8900884 44
tmccurbin 36:8544a8900884 45 int main()
tmccurbin 36:8544a8900884 46 {
tmccurbin 36:8544a8900884 47 wait(1);
tmccurbin 36:8544a8900884 48
tmccurbin 36:8544a8900884 49 Thread thread(update_x);
tmccurbin 36:8544a8900884 50
tmccurbin 36:8544a8900884 51 Thread thread2(update_y);
tmccurbin 36:8544a8900884 52
tmccurbin 36:8544a8900884 53
tmccurbin 36:8544a8900884 54 display.PutString(0, 42, "Live Test");
tmccurbin 36:8544a8900884 55
tmccurbin 36:8544a8900884 56 PUT2SCREEN("CAN-1:", CAN1Buffer, "", 3, 0, 30);
tmccurbin 36:8544a8900884 57 PUT2SCREEN("CAN-2:", CAN2Buffer, "", 3, 77,107);
tmccurbin 36:8544a8900884 58
tmccurbin 36:8544a8900884 59
tmccurbin 36:8544a8900884 60
tmccurbin 36:8544a8900884 61 PUT2SCREEN("CAN-3:", CAN3Buffer, "", 5, 0, 30);
tmccurbin 36:8544a8900884 62 PUT2SCREEN("CAN-4:", CAN4Buffer, "", 5, 77,107);
tmccurbin 36:8544a8900884 63
tmccurbin 36:8544a8900884 64 while (1) {
tmccurbin 36:8544a8900884 65 printf("x = %d y = %f\n", x, y); //9600 baud (default)
tmccurbin 36:8544a8900884 66
tmccurbin 36:8544a8900884 67 ledBar = y*(2.7/3.3);
tmccurbin 36:8544a8900884 68
tmccurbin 36:8544a8900884 69 if (abs(diff) >= threshold) {
tmccurbin 36:8544a8900884 70 display.GotoXY(30,24);
tmccurbin 36:8544a8900884 71 //display.PutString(3,30, " ");
tmccurbin 36:8544a8900884 72 display.PrintInteger(x,3,30);
tmccurbin 36:8544a8900884 73 display.PrintInteger(x,3,107);
tmccurbin 36:8544a8900884 74 display.PrintInteger(x,5,30);
tmccurbin 36:8544a8900884 75 display.PrintInteger(x,5,107);
tmccurbin 36:8544a8900884 76 x_old = x_new;
tmccurbin 36:8544a8900884 77 }
tmccurbin 36:8544a8900884 78 }
tmccurbin 36:8544a8900884 79
tmccurbin 36:8544a8900884 80 }
tmccurbin 36:8544a8900884 81 // FORMAT_CODE_END
kiran_mbed 42:701df58e923a 82 // FORMAT_CODE_END
kiran_mbed 42:701df58e923a 83 */