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.
Revision 0:aa02ddcd8bc3, committed 2016-03-30
- Comitter:
- TheDoctor822
- Date:
- Wed Mar 30 17:21:37 2016 +0000
- Commit message:
- SUH DUDE
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Wed Mar 30 17:21:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Mar 30 17:21:37 2016 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "C12832_lcd.h"
+Serial pc(USBTX, USBRX); // tx, rx
+
+C12832_LCD lcd;
+
+AnalogIn pot1( p19 );
+PwmOut servo( p21 );
+I2C compass( p28, p27);
+Ticker tick100hz;
+Ticker tick5hz;
+
+const int compass_addr = 0x42;
+char cmd[3];
+char compass_raw[2];
+float pos = 0;
+float ctrlval = 0;
+float PWM_zero = .072;
+
+float north = 0.0;
+float err, error_int;
+float error_old = 0.0;
+float error_int_old = 0.0;
+float T = 0.01;
+float baseline = -90.0;
+
+float kp = 0.00015; // Decreasing kp made the adjustments smaller and smoother
+float ki = 0.0;
+
+
+void s100hz_task(void) {
+
+ compass.read ( compass_addr, compass_raw, 2 );
+ pos = 0.1*(( compass_raw[0]<<8) + compass_raw[1] ) -90;
+ if ( pos>180 ) {
+ pos = pos -360;
+
+ }
+ //ctrlval = pot1.read() * .05;
+ north = baseline + pot1.read() * 180.0 ;
+ err = pos - north;
+ error_int = error_int_old + .5 * (err + error_old) * T ;
+ ctrlval = kp * err + ki * error_int;
+ ctrlval = ctrlval + PWM_zero;
+ error_old = err;
+ error_int_old = error_int;
+
+
+
+ servo = ctrlval;
+}
+
+void s5hz_task ( void ) {
+
+ //lcd.locate (0, 0);
+
+ pc.printf ( "Position: %f, Control Duty Cycle: %f, North: %f \n", pos, ctrlval, north);
+}
+
+int main() {
+
+ cmd[0] = 0x47;
+ cmd[1] = 0x74;
+ cmd[2] = 0x72;
+
+ compass.write ( compass_addr, cmd, 3 );
+
+ tick100hz.attach ( &s100hz_task, .01 );
+ tick5hz.attach ( &s5hz_task, .2 );
+
+ while (1) {
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 30 17:21:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/c0f6e94411f5 \ No newline at end of file