Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 // TBRe-AI FRONT MBED 00002 // MONITORS STEERING ANGLE AND WHEEL SPEED 00003 // AND SENDS THEM OVER CAN BUS 00004 // WRITTEN BY SEB HALL ON 29/06/2022 00005 00006 #include "mbed.h" 00007 00008 const PinName writePin = p29; 00009 const PinName readPin = p30; 00010 const int busFrequency = 500000; 00011 const unsigned int steeringMessageID = 100; 00012 00013 DigitalOut led1(LED1); 00014 DigitalOut led2(LED2); 00015 Serial pc(USBTX, USBRX); 00016 AnalogIn steeringIn(p15); 00017 00018 union { 00019 double formattedData; 00020 unsigned char rawData[8]; 00021 } CANFormatted; 00022 00023 CAN CANBus(readPin, writePin, busFrequency); 00024 00025 void sendCANMessage(double data, unsigned int id) { 00026 00027 CANMessage message; 00028 00029 CANFormatted.formattedData = data; 00030 00031 for (int i = 0; i < 8; i++) { 00032 message.data[i] = CANFormatted.rawData[i]; 00033 } 00034 00035 message.id = id; 00036 00037 CANBus.write(message); 00038 00039 } 00040 00041 int main() { 00042 pc.printf("FRONT STARTED\n"); 00043 led1 = !led1; 00044 while(1) { 00045 float num = (float) steeringIn.read(); 00046 sendCANMessage(num, steeringMessageID); 00047 led1 = !led1; 00048 led2 = !led2; 00049 } 00050 }
Generated on Sun Aug 7 2022 13:59:59 by
1.7.2