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
Diff: main.cpp
- Revision:
- 4:54544a7dcbe0
- Parent:
- 3:147e7a35d2c3
- Child:
- 5:66527172b136
--- a/main.cpp Thu Feb 16 17:33:01 2017 +0000
+++ b/main.cpp Fri Feb 17 01:34:30 2017 +0000
@@ -3,16 +3,19 @@
#define MAX 0x0A
-DigitalOut led_1(LED1); //program running.
-DigitalOut led_2(LED2); //sensors operating.
-DigitalOut led_3(LED3); //is moving.
-DigitalOut led_4(LED4); //is complete.
+DigitalOut led_1(LED1); // program running.
+DigitalOut led_2(LED2); // sensors operating.
+DigitalOut led_3(LED3); // is moving.
+DigitalOut led_4(LED4); // is complete.
-DigitalOut Bit1(p25); // mux/ pins
+PwmOut steer(p21); // Pulse width modulation pins that control direction
+PwmOut speed(p22); // and speed
+
+DigitalOut Bit1(p25); // multiplexor pins
DigitalOut Bit2(p24); //
DigitalOut Bit3(p23); //
-int rawUS_data[5]={0,0,0,0,0}; //raw data{chan1,chan2,chan3,chan4,chan5}
+int rawUS_data[5]={0,0,0,0,0}; // raw data{chan1,chan2,chan3,chan4,chan5}
int US1_mean[MAX]={0,0,0,0,0,0,0,0,0,0}; // Structures holding recently recorded distances for each respective
int US2_mean[MAX]={0,0,0,0,0,0,0,0,0,0}; // ultrasonic sensor.
@@ -20,11 +23,11 @@
int US4_mean[MAX]={0,0,0,0,0,0,0,0,0,0};
int US5_mean[MAX]={0,0,0,0,0,0,0,0,0,0};
-std::string telemFile; //file holding info about telem data gathered since last power on
+std::string telemFile; // file holding info about telem data gathered since last power on
void setActiveUS(int chan);
-int getPing(void);
+int getPing();
int main() {
int iCount = 0;
@@ -35,7 +38,7 @@
measured = getPing();
rawUS_data[iCount] = measured;
}
-
+
US1_mean[0]=rawUS_data[0];
US2_mean[0]=rawUS_data[1];
US3_mean[0]=rawUS_data[2];
@@ -69,19 +72,40 @@
}
}
-int getPing(void){
+int getPing(){
int result=0;
//write ultrasonic code
//return measured value
-
return result; //should just do "return [operation that gives result];" for efficiency
}
// Opens set file for logging, appends some data, then returns.
-//
-void telemSave(std::string data) {
+// This method is only called for speed and heading changes.
+void telemUpdate(float steer, float speed) {
+ std::ofstream stream;
+ stream.open(telemFile, std::ios::app);
+ stream << "steer:" << data << " speed:" << speed << "\n";
+}
+
+// Opens set file for logging, appends some data, then returns.
+// This method is only called for ambient temperature readings.
+void telemUpdate(float temp) {
std::ofstream stream;
stream.open(telemFile, std::ios::app);
- stream << data;
-}
\ No newline at end of file
+ stream << "temp: " << temp << "\n";
+}
+
+// Alters the cars steering angle based on the float passed to it.
+// Float s is valued between -1 and +1. ERRONEOUS VALUES ARE IGNORED.
+void turnWheels(float s) {
+ if (s++>=0&&s<=2) {steer.pulsewidth(s/2000+0.001}} // This is Nicolae's code, simplified and included by Frank
+ telemUpdate()
+}
+
+// Alters the cars velocity based on the float passed to it.
+// Float s is valued between -1 and +1. ERRONEOUS VALUES ARE IGNORED.
+void setSpeed(float s) {
+ if (s++>=0&&s<=2) {speed.pulsewidth(s/2000+0.001)} // THIS CODE IS NOT VERY GOOD and will not work without changes
+ telemUpdate() // Someone who knows how PWM works - fix this please
+}