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.
Diff: main.cpp
- Revision:
- 3:010fde11bfad
- Parent:
- 2:f5c2fa19497b
- Child:
- 4:ece7bfb06944
--- a/main.cpp Wed Nov 28 18:48:00 2018 +0000
+++ b/main.cpp Wed Nov 28 20:42:49 2018 +0000
@@ -35,6 +35,7 @@
DigitalOut r_dir( p21 );
DigitalOut r_I(p23);
DigitalOut r_slp(p30); //sleep
+DigitalOut slp(p29);
DigitalOut led(LED1);
float r_ang;
float r_pos;
@@ -47,10 +48,11 @@
int main(void)
{
- r_I=0;
- rudder.period(.001);
- rudder.pulsewidth(0);
- r_slp = 0;
+ r_I=0; //sets for 1.5amp output
+ rudder.period(.001); //sets the pulse width modulation period
+ rudder.pulsewidth(0);
+ slp = 0;
+ r_slp = 0; //sstarts the current driver in off state
wait(10);
led = 1; //indicate that the wait period is over
@@ -61,40 +63,60 @@
if (rx.valid) {
RC_1 = rx.channel[1];
- pc.printf(" rc: %f\n",rx.channel[0]);
+ //pc.printf(" rc: %f\n",rx.channel[0]);
} else {
- pc.printf(" invalid\r\n");
+ //pc.printf(" invalid\r\n");
r_slp = 0;
}
//39.19
- r_ang = (RC_1/6.77)+30.0;
+ r_ang = (RC_1/6.77)-5.0;
r_pos = (r_ain-.108)/.002466;
+ pc.printf(" %.3f\r\n",r_pos);
//pc.printf(" %.3f\n",);
if((r_pos > (r_ang-3.0)) && (r_pos < (r_ang+3.0))) {
rudder.pulsewidth(0);
r_slp = 0;
}
- if( (r_pos > (r_ang+3.0)) && r_pos < 270.0) {
+ if( (r_pos > (r_ang+3.0)) && r_pos < 235.0) {
r_slp = 1;
while(r_pos > r_ang) {
r_dir = 1; //left??
rudder.pulsewidth(.0005);
- pc.printf("pos: %.3f\n",r_pos);
+ //pc.printf("pos: %.3f\n",r_pos);
r_pos = posr();
}//while pos
rudder.pulsewidth(0);
}//if pos
- if((r_pos < (r_ang-3.0)) && r_pos > 90.0) {
+ if((r_pos < (r_ang-3.0)) && r_pos > 55.0) {
r_slp = 1;
while(r_pos < r_ang) {
r_dir = 0; //right??
rudder.pulsewidth(.0005);
- pc.printf("pos: %.3f\n",r_pos);
+ //pc.printf("pos: %.3f\n",r_pos);
r_pos = posr();
}//while pos
rudder.pulsewidth(0);
}
+ if(r_pos > 210.0){
+ r_slp = 1;
+ while(r_pos > 210.0) {
+ r_dir = 1; //right??
+ rudder.pulsewidth(.0005);
+ //pc.printf("pos: %.3f\n",r_pos);
+ r_pos = posr();
+ }//while
+ }//if
+ if(r_pos <80.0){
+ r_slp = 1;
+ while(r_pos < 80.0) {
+ r_dir = 0; //right??
+ rudder.pulsewidth(.0005);
+ //pc.printf("pos: %.3f\n",r_pos);
+ r_pos = posr();
+ }//while
+ }//if
+
//***END OF JUST ADDED
ThisThread::sleep_until(121);
}//while(1)