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: thruster.cpp
- Revision:
- 4:d32183587460
- Parent:
- 3:02a9d402226d
- Child:
- 5:e0c525588568
--- a/thruster.cpp Tue Nov 24 13:22:47 2020 +0000
+++ b/thruster.cpp Fri Apr 09 11:38:56 2021 +0000
@@ -8,6 +8,7 @@
*
*/
+#include "mbed.h"
#include "thruster.h"
//Instantiation accepts PWM pin and direction of prop blade
@@ -20,7 +21,7 @@
set_pw(_base_pw); // set PWM to 1.5ms
_period=2.5; // 2.5ms
set_period(_period); // set period to 2.5ms (400Hz)
- _max=150; // max PWM value
+ _max=150; // max PWM value in us
//printf("Thruster: %f\r\n",d);
}
@@ -65,7 +66,7 @@
//formats PWM as an 2 uint16_t joined to make uint32_t for serial data streaming
//MSB uint16_t indicates direction, 0 for positive, 1 for negative.
-//LSB uint16_t is 10ms resolution of PWM
+//LSB uint16_t is 10us resolution of PWM
uint32_t Thruster::thruster_data() {
double speed=get_speed();
uint32_t dir=0x0;
@@ -76,18 +77,20 @@
return data;
}
-//Accepts adjustment to max value of pw [x,500] ms for set_speed() function.
+//Accepts adjustment to max value of pw [x,500] us for set_speed() function.
//Returns 1 if successful.
-int Thruster::set_max(double new_max) {
- int returnval=0;
- if (new_max<500) {
+void Thruster::set_max(int new_max) {
+ if (new_max<=500) {
_max=new_max;
- returnval=1;
}
- return returnval;
}
-//Accepts adjustment to pw [-500,500] ms that is added to 1.5ms.
+int Thruster::get_max() {
+ int buffer = _max;
+ return buffer;
+}
+
+//Accepts adjustment to pw [-500,500] us that is added to 1.5ms.
//Returns 1 if successful.
int Thruster::set_speed(double speed_pw) {
int returnval = 0;