Dual Brushless Motor ESC, 10-62V, up to 50A per motor. Motors ganged or independent, multiple control input methods, cycle-by-cycle current limit, speed mode and torque mode control. Motors tiny to kW. Speed limit and other parameters easily set in firmware. As used in 'The Brushless Brutalist' locomotive - www.jons-workshop.com. See also Model Engineer magazine June-October 2019.
Dependencies: mbed BufferedSerial Servo PCT2075 FastPWM
Update 17th August 2020 Radio control inputs completed
Diff: cli_BLS_nortos.cpp
- Revision:
- 11:bfb73f083009
- Parent:
- 10:e40d8724268a
- Child:
- 12:d1d21a2941ef
--- a/cli_BLS_nortos.cpp Tue Jan 15 09:03:57 2019 +0000
+++ b/cli_BLS_nortos.cpp Sat Jan 19 11:45:01 2019 +0000
@@ -1,6 +1,9 @@
// DualBLS2018_06
#include "mbed.h"
#include "BufferedSerial.h"
+#include "FastPWM.h"
+#include "DualBLS.h"
+#include "brushless_motor.h"
#include <cctype>
#include "DualBLS.h"
@@ -11,6 +14,8 @@
extern bool WatchDogEnable;
extern char mode_bytes[];
+extern brushless_motor MotorA, MotorB;
+
const int BROADCAST = '\r';
const int MAX_PARAMS = 20;
struct parameters {
@@ -30,10 +35,11 @@
extern void setVI (double v, double i) ;
extern void setV (double v) ;
extern void setI (double i) ;
-extern void read_last_VI (double * val) ; // only for test from cli
+//extern void last_VI (double * val) ; // only for test from cli
//BufferedSerial * com;
extern double Read_DriverPot ();
+extern double Read_BatteryVolts ();
void pot_cmd (struct parameters & a)
{
pc.printf ("Driver's pot %.3f\r\n", Read_DriverPot ());
@@ -69,12 +75,6 @@
a.com->printf ("Watchdog %sabled\r\n", WatchDogEnable ? "En":"Dis");
}
-extern void prscfuck (int);
-void pf_cmd (struct parameters & a)
-{
- prscfuck ((int)a.dbl[0]);
-}
-
extern void report_motor_types () ;
void mt_cmd (struct parameters & a)
{
@@ -84,24 +84,17 @@
}
extern void mode_set_both_motors (int mode, double val) ; // called from cli to set fw, re, rb, hb
-extern void read_supply_vi (double * val) ;
void rdi_cmd (struct parameters & a) // read motor currents
{
- if (a.respond) {
- double r[4];
- read_supply_vi (r); // get MotorA.I.ave, MotorB.I.ave, Battery volts
- a.com->printf ("rdi%.0f %.0f %.1f\r", r[0], r[1], r[2]); // Format good to be unpicked by cli in touch screen controller
- }
+ if (a.respond)
+ a.com->printf ("rdi%.0f %.0f %.1f\r", MotorA.I.ave, MotorB.I.ave, Read_BatteryVolts ()); // Format good to be unpicked by cli in touch screen controller
}
void rvi_cmd (struct parameters & a) // read last normalised values sent to pwms
{
- if (a.respond) {
- double r[6];
- read_last_VI (r);
- a.com->printf ("rvi%.2f %.2f %.2f %.2f\r", r[0], r[1], r[2], r[3]);
- }
+ if (a.respond)
+ a.com->printf ("rvi%.2f %.2f %.2f %.2f\r", MotorA.last_V, MotorA.last_I, MotorB.last_V, MotorB.last_I);
}
void fw_cmd (struct parameters & a) // Forward command
@@ -233,24 +226,17 @@
}
}
-extern void read_RPM (uint32_t * dest) ;
void rpm_cmd (struct parameters & a) // to report e.g. RPM 1000 1000 ; speed for both motors
{
- if (a.respond) {
- uint32_t dest[3];
- read_RPM (dest); // gets rpm for each motor
- a.com->printf ("rpm%d %d\r", dest[0], dest[1]);
- }
+ if (a.respond)
+ a.com->printf ("rpm%d %d\r", MotorA.RPM, MotorB.RPM);
}
extern double rpm2mph ;
void mph_cmd (struct parameters & a) // to report miles per hour
{
- if (a.respond) {
- uint32_t dest[3];
- read_RPM (dest); // gets rpm for each motor
- a.com->printf ("mph%c %.3f\r", mode_bytes[ID], (double)(dest[0] + dest[1]) * rpm2mph / 2.0);
- }
+ if (a.respond)
+ a.com->printf ("mph%c %.3f\r", mode_bytes[ID], (double)(MotorA.RPM + MotorB.RPM) * rpm2mph / 2.0);
}
void menucmd (struct parameters & a);
@@ -343,7 +329,6 @@
{"ls", "Lists available commands", menucmd},
{"?", "Lists available commands, same as ls", menucmd},
{"mtypes", "report types of motors found", mt_cmd},
- {"pf", "try changing FastPWM prescaler values", pf_cmd},
{"pot", "read drivers control pot", pot_cmd},
{"fw", "forward", fw_cmd},
{"re", "reverse", re_cmd},
@@ -405,7 +390,7 @@
*/
//void command_line_interpreter (void const *argument)
void cli_core (struct parameters & a) {
- const int MAX_CMD_LEN = 120;
+ const int MAX_CMD_LEN = 180;
int ch, IAm = I_Am();
char * pEnd;//, * cmd_line_ptr;
while (a.com->readable()) {
@@ -414,8 +399,10 @@
a.com->printf ("Error!! Stupidly long cmd line\r\n");
a.cl_index = 0;
}
- if(ch != '\r') // was this the 'Enter' key?
- a.cmd_line[a.cl_index++] = ch; // added char to command being assembled
+ if(ch != '\r') { // was this the 'Enter' key?
+ if (ch != '\n') // Ignore line feeds
+ a.cmd_line[a.cl_index++] = ch; // added char to command being assembled
+ }
else { // key was CR, may or may not be command to lookup
a.target_unit = BROADCAST; // Set to BROADCAST default once found command line '\r'
a.cmd_line_ptr = a.cmd_line;