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: FRDM-TFC mbed CBuffer XBEE mbed_angular_speed motor2 MMA8451Q
Fork of KL25Z_Camera_Test by
Revision 41:d74878640739, committed 2017-01-25
- Comitter:
- FatCookies
- Date:
- Wed Jan 25 15:46:50 2017 +0000
- Parent:
- 40:10e8e80af7da
- Child:
- 42:4395ede5781e
- Child:
- 43:649473c5a12b
- Commit message:
- readFloat function added
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jan 21 11:59:20 2017 +0000
+++ b/main.cpp Wed Jan 25 15:46:50 2017 +0000
@@ -504,6 +504,14 @@
}
+float readFloat() {
+ byte_float_union.bytes[0] = xb.cBuffer->read();
+ byte_float_union.bytes[1] = xb.cBuffer->read();
+ byte_float_union.bytes[2] = xb.cBuffer->read();
+ byte_float_union.bytes[3] = xb.cBuffer->read();
+ return byte_float_union._float;
+}
+
// Listen for incoming commands from telemetry program and change car variables
inline void handleComms() {
if(curr_cmd != 0) {
@@ -511,24 +519,10 @@
// Change the PID values of the servo controller
case CHANGE_PID:
if(xb.cBuffer->available() >= 12) {
-
- byte_float_union.bytes[0] = xb.cBuffer->read();
- byte_float_union.bytes[1] = xb.cBuffer->read();
- byte_float_union.bytes[2] = xb.cBuffer->read();
- byte_float_union.bytes[3] = xb.cBuffer->read();
- servo_pid.Kp = byte_float_union._float;
- byte_float_union.bytes[0] = xb.cBuffer->read();
- byte_float_union.bytes[1] = xb.cBuffer->read();
- byte_float_union.bytes[2] = xb.cBuffer->read();
- byte_float_union.bytes[3] = xb.cBuffer->read();
- servo_pid.Ki = byte_float_union._float;
-
- byte_float_union.bytes[0] = xb.cBuffer->read();
- byte_float_union.bytes[1] = xb.cBuffer->read();
- byte_float_union.bytes[2] = xb.cBuffer->read();
- byte_float_union.bytes[3] = xb.cBuffer->read();
- servo_pid.Kd = byte_float_union._float;
+ servo_pid.Kp = readFloat();
+ servo_pid.Ki = readFloat();
+ servo_pid.Kd = readFloat();
sendString("pid= Kp: %f, Ki: %f, Kd: %f", servo_pid.Kp, servo_pid.Ki, servo_pid.Kd);
@@ -551,11 +545,7 @@
// Change the electronic differential coefficient
case CHANGE_ED:
if(xb.cBuffer->available() >= 4) {
- byte_float_union.bytes[0] = xb.cBuffer->read();
- byte_float_union.bytes[1] = xb.cBuffer->read();
- byte_float_union.bytes[2] = xb.cBuffer->read();
- byte_float_union.bytes[3] = xb.cBuffer->read();
- ed_tune = byte_float_union._float;
+ ed_tune = readFloat();
curr_cmd = 0;
}
break;
--- a/main.h Sat Jan 21 11:59:20 2017 +0000
+++ b/main.h Wed Jan 25 15:46:50 2017 +0000
@@ -42,6 +42,7 @@
float output;
} pid_instance;
+extern float readFloat();
extern inline void handleComms();
extern void sendString(const char *format, ...);
extern inline void sendImage();
