Railway Challenge / Mbed 2 deprecated challenge

Dependencies:   mbed millis

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motor.cpp Source File

motor.cpp

00001 #include <mbed.h>
00002 #include "definitions.h"
00003 #include "motor.h"
00004 
00005 Motor::Motor   (AnalogOut& motorAccelerator,
00006                 AnalogOut& motorBrake,
00007                 DigitalOut& keySwitch,
00008                 DigitalOut& directionFwd,
00009                 DigitalOut& directionRev,
00010                 DigitalOut& footSwitch,
00011                 DigitalOut& seatSwitch,
00012                 DigitalOut& inchFwd,
00013                 DigitalOut& speedLimit2,
00014                 DigitalOut& speedLimit3) : 
00015                 
00016                 _motorAccelerator(motorAccelerator),
00017                 _motorBrake(motorBrake),
00018                 _keySwitch(keySwitch),
00019                 _directionFwd(directionFwd),
00020                 _directionRev(directionRev),
00021                 _footSwitch(footSwitch),
00022                 _seatSwitch(seatSwitch),
00023                 _inchFwd(inchFwd),
00024                 _speedLimit2(speedLimit2),
00025                 _speedLimit3(speedLimit3)
00026                 {
00027                     _motorAccelerator = 0;
00028                     _motorBrake = 0;
00029 //                    _contactMtr = 0;
00030                     _keySwitch = 0;
00031                     _directionFwd = 0;
00032                     _directionRev = 0;
00033                     _footSwitch = 0;
00034                     _seatSwitch = 0;
00035                     _inchFwd = 1;
00036                     _speedLimit2 = 1;
00037                     _speedLimit3 = 0;   // SET MAX SPEED MODE BY DEFAULT
00038                 }
00039 
00040 
00041 void Motor::turnOn() {
00042     _keySwitch = 1;
00043 //    pc.printf("Motor Switched On\r\n");  
00044 }
00045 
00046 void Motor::turnOff() {
00047     _keySwitch = 0;
00048 //    pc.printf("Motor Switched Off\r\n");  
00049 }
00050 
00051 void Motor::closeDeadman() {
00052     _footSwitch = 1;
00053     _seatSwitch = 1;
00054 }
00055 
00056 void Motor::releaseDeadman() {
00057     _footSwitch = 0;
00058     _seatSwitch = 0;
00059 }
00060 
00061 void Motor::setForward() {
00062     _directionFwd = 1;
00063     _directionRev = 0;
00064 //    pc.printf("Motor Set to Forward\r\n");  
00065 }
00066 
00067 void Motor::setPark() {
00068     _directionFwd = 0;
00069     _directionRev = 0;
00070     
00071 //    pc.printf("Motor Set to Park\r\n"); 
00072 }
00073 
00074 void Motor::setReverse() {
00075     _directionFwd = 0;
00076     _directionRev = 1;
00077 //    pc.printf("Motor Set to Reverse\r\n"); 
00078 }
00079 
00080 void Motor::engage() {
00081 //    _contactMtr = 1;    
00082 //    pc.printf("Motor Contactor Engaged\r\n");   
00083 }
00084 
00085 void Motor::disengage() {
00086 //    _contactMtr = 0;
00087     
00088     setPark();
00089     
00090 //    pc.printf("Motor Disengaged\r\n");  
00091 }
00092 
00093 void Motor::setSpeedMode(int speed) {
00094     switch (speed) {
00095         case 0:     // Clear limits
00096         
00097             _inchFwd = 0;
00098             _speedLimit2 = 0;
00099             _speedLimit3 = 0;
00100             
00101 //                    pc.printf("Motor Speed Cleared\r\n");
00102             break;
00103         
00104         case 1:     // Inch Forward
00105         
00106             _inchFwd = 1;
00107             _speedLimit2 = 0;
00108             _speedLimit3 = 0;
00109             
00110 //                    pc.printf("Motor Set to Inch Forward\r\n");
00111             break;
00112             
00113         case 2:     // Speed 2
00114             
00115             _inchFwd = 0;
00116             _speedLimit2 = 1;
00117             _speedLimit3 = 0;
00118             
00119 //                    pc.printf("Motor Set to Speed Limit 2\r\n");
00120             break;
00121             
00122         case 3:     // Speed 3
00123             
00124             _inchFwd = 0;
00125             _speedLimit2 = 0;
00126             _speedLimit3 = 1;
00127             
00128 //            pc.printf("Motor Set to Speed Limit 3\r\n");
00129             break;   
00130     }
00131 }
00132 
00133 void Motor::throttle(float throttleRate) {
00134     // set the output voltage of the analog output pin specified as a percentage of Vcc (3.3V)
00135     _motorAccelerator = throttleRate;   // Analog value between 0.0f and 1.0f
00136 //    pc.printf("Throttling\r\n");
00137     
00138 }
00139 
00140 void Motor::brake(float brakeRate) {
00141     _motorBrake = brakeRate;            // Analog value between 0.0f and 1.0f
00142 //    pc.printf("Motor Braking\r\n");
00143 }