new battery bar
Dependencies: CAN_IDs CanControl Dashboard PinDetect PowerControl mbed-rtos mbed
Revision 14:0ad1bc8be76b, committed 2017-05-22
- Comitter:
- zathorix
- Date:
- Mon May 22 15:16:34 2017 +0000
- Parent:
- 11:005a50dd7db5
- Child:
- 15:56b25cffa523
- Commit message:
- throttle working
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CAN_IDs.lib Mon May 22 15:16:34 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Solarboat-Twente/code/CAN_IDs/#776e57f7ca89
--- a/main.cpp Sun May 21 22:00:52 2017 +0000 +++ b/main.cpp Mon May 22 15:16:34 2017 +0000 @@ -23,8 +23,11 @@ // include Solarboat libraries #include "pinout.h" +#include "CAN_IDs.h" #include "PowerControl.h" +#define SPEED_THRESH 0.05 + // initialize serial connection for debug #ifdef DEBUG RawSerial pc(SERIAL_TX, SERIAL_RX); @@ -33,6 +36,9 @@ // initialize canbus CAN can(CAN_RD, CAN_TD); +//init throttle +AnalogIn analogThrottle(STEER_THROTTLE); + // initialze onboard leds DigitalOut ledError(LED3); DigitalOut ledSD(LED1); @@ -68,11 +74,34 @@ buckScreen = 0; buck24V = 1; - - - } +float speed = 0; + +//send motor command +void sendMotorSpeed(float throttle) { + if ((abs(throttle - speed)) > SPEED_THRESH) { + union { + char msg[4]; + float value; + } packet; + packet.value = throttle; + can.write(CANMessage(MOTOR_COMMAND, packet.msg)); + printf("Sent motor speed: %f\r\n", packet.value); + speed = throttle; + } +} + +//throttle thread +void readThrottle() { + float throttleread; + while(1) { + throttleread = floor(2*(0.5 - analogThrottle.read())*1000)/1000; + sendMotorSpeed(throttleread); + Thread::wait(100); + } +} + // Thread 0 - DO NOT CHANGE THIS! int main() { #ifdef DEBUG @@ -88,6 +117,7 @@ //Thread thread3; //Thread thread4; Thread threadx; + Thread threadthrottle; // change thread priority //thread2.set_priority(osPriorityBelowNormal); @@ -98,6 +128,7 @@ //thread3.start(&motorTest); //thread4.start(&canReceive); threadx.start(&test); + threadthrottle.start(&readThrottle); //stop this thread while keeping the other threads running CANMessage msg;
--- a/pinout.h Sun May 21 22:00:52 2017 +0000 +++ b/pinout.h Mon May 22 15:16:34 2017 +0000 @@ -104,11 +104,11 @@ // Steering wheel -#define STEER_THROTTLE PB_12 +#define STEER_THROTTLE PC_5 -#define STEER_SW1 PC_5 -#define STEER_SW2 PA_12 -#define STEER_SW3 PA_11 +#define STEER_FLY PC_6 +#define STEER_REV PA_12 +#define STEER_MENU PA_11 // Others