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

Revision:
13:ef7a06fa11de
Parent:
12:d1d21a2941ef
Child:
14:acaa1add097b
--- a/cli_BLS_nortos.cpp	Mon Mar 04 17:51:08 2019 +0000
+++ b/cli_BLS_nortos.cpp	Sun Sep 29 16:34:37 2019 +0000
@@ -18,7 +18,7 @@
 //  Brushless_STM3_Ctrl_2018_11
 #include "mbed.h"
 #include "BufferedSerial.h"
-#include "DualBLS.h"
+#include "STM3_ESC.h"
 #include "brushless_motor.h"
 
 #include <cctype>
@@ -26,8 +26,8 @@
 
 extern  eeprom_settings     mode     ;
 extern  error_handling_Jan_2019     ESC_Error    ;         //  Provides array usable to store error codes.
-extern  int     WatchDog;
-extern  bool    WatchDogEnable;
+extern  int     WatchDog;           //  from main
+extern  bool    WatchDogEnable;     //  from main
 extern  double  rpm2mph ;
 
 extern  brushless_motor MotorA, MotorB;     //  Controlling two motors together or individually
@@ -202,9 +202,9 @@
                 break;
             case    2:      //  MotorA_ current sense resistors [1 to 4], MotorB_ current sense resistors [1 to 4]
                 if  (temps[1] > 0 && temps[1] < 5) 
-                    mode.wr(temps[1], MOTADIR);
+                    mode.wr(temps[1], ISHUNTA);     //  Corrected since published
                 if  (temps[2] > 0 && temps[2] < 5)  
-                    mode.wr(temps[2], MOTBDIR);
+                    mode.wr(temps[2], ISHUNTB);
                 break;
             case    3:      //  2 Servo1 [0 or 1], Servo2 [0 or 1]
                 if  (temps[1] == 0 || temps[1] == 1)
@@ -265,6 +265,16 @@
 
 }
 
+
+void    ssl_cmd  (struct parameters & a)  {     //  set speed limit NEW and untested July 2019
+    if  (a.dbl[0] > 25.0)   a.dbl[0] = 25.0;
+    if  (a.dbl[0] < 1.0)    a.dbl[0] = 1.0;
+    mode.wr((char)(a.dbl[0] * 10.0), TOP_SPEED);
+    mode.save   ();
+}
+
+#ifdef  TEMP_SENSOR_ENABLE
+
 extern  uint32_t    last_temperature_count;
 /**
 *   void    temperature_cmd  (struct parameters & a)  {
@@ -275,6 +285,7 @@
         a.com->printf ("tem%c %d\r\n", mode.rd(BOARD_ID), (last_temperature_count / 16) - 50);
     }
 }
+#endif
 
 /**
 *void    rpm_cmd (struct parameters & a) //  to report e.g. RPM 1000 1000 ; speed for both motors
@@ -352,6 +363,10 @@
 /**
 *void    kd_cmd (struct parameters & a)  //  kick and enable the watch dog
 *
+*   Brute_TS_Controller or other external controller to issue regular 'kd\r' to come here.
+*   WatchDog disabled by default, enabled on first call to here
+*   This is where WatchDog timer is reset and reloaded.
+*   Timeout may be detected and handled in 8Hz loop in main programme loop
 */
 void    kd_cmd (struct parameters & a)  //  kick the watchdog. Reached from TS or pc.
 {
@@ -359,6 +374,10 @@
     WatchDogEnable = true;                          //  Receipt of this command sufficient to enable watchdog
 }
 
+void    wd_report (struct parameters & a)     //  Reachable always from pc. Only addressed board responds to TS
+{
+    pc.printf   ("WatchDog %d\r\n", WatchDog);
+}
 /**
 *void    who_cmd (struct parameters & a)     //  Reachable always from pc. Only addressed board responds to TS
 *
@@ -386,16 +405,16 @@
 {
     switch  ((int)a.dbl[0]) {
         case    1:
-            MotorA.s[1] = MotorB.s[1] = a.dbl[1];
+            MotorA.sdbl[1] = MotorB.sdbl[1] = a.dbl[1];
             break;
         case    2:
-            MotorA.s[2] = MotorB.s[2] = a.dbl[1];
+            MotorA.sdbl[2] = MotorB.sdbl[2] = a.dbl[1];
             break;
         case    3:
-            MotorA.s[3] = MotorB.s[3] = a.dbl[1];
+            MotorA.sdbl[3] = MotorB.sdbl[3] = a.dbl[1];
             break;
         case    4:
-            MotorA.s[4] = MotorB.s[4] = a.dbl[1];
+            MotorA.sdbl[4] = MotorB.sdbl[4] = a.dbl[1];
             break;
         case    5:
             MotorA.set_speed    (a.dbl[1]);
@@ -404,11 +423,12 @@
         default:
             pc.printf   ("Wrong use of scmd %f\r\n", a.dbl[0]);
     }
+    pc.printf   ("Filter Coefficient Fiddler - used in brushless_motor::speed_monitor_and_control   ()");
     pc.printf   ("Filter Coeffs 1 to 4\r\n");
-    pc.printf   ("1 %.3f\tPscale 0.01-0.5\r\n",     MotorA.s[1]);
-    pc.printf   ("2 %.3f\tP_gain 1.0-1000.0\r\n",   MotorA.s[2]);
-    pc.printf   ("3 %.3f\tDscale 0.01-0.5\r\n",     MotorA.s[3]);
-    pc.printf   ("4 %.3f\tD_gain 1.0-1000.0\r\n",   MotorA.s[4]);
+    pc.printf   ("1 %.3f\tPscale 0.01-0.5\r\n",     MotorA.sdbl[1]);
+    pc.printf   ("2 %.3f\tP_gain 1.0-1000.0\r\n",   MotorA.sdbl[2]);
+    pc.printf   ("3 %.3f\tDscale 0.01-0.5\r\n",     MotorA.sdbl[3]);
+    pc.printf   ("4 %.3f\tD_gain 1.0-1000.0\r\n",   MotorA.sdbl[4]);
     pc.printf   ("5 Set target_speed\r\n");
 }
 
@@ -456,8 +476,11 @@
     {"?v", "Report system bus voltage", sysV_report},
     {"?i", "Report motor both currents", sysI_report},
     {"who", "search for connected units, e.g. 3who returs 'who3' if found", who_cmd},
+#ifdef  TEMP_SENSOR_ENABLE
     {"tem", "report temperature", temperature_cmd},
+#endif
     {"mph", "read loco speed miles per hour", mph_cmd},
+    {"ssl", "set speed limit e.g. 10.7", ssl_cmd},              //  NEW July 2019
 //    {"rvi", "read most recent values sent to pwms", rvi_cmd},
 //    {"rdi", "read motor currents and power voltage", rdi_cmd},
     //  ***** Endof
@@ -474,7 +497,7 @@
 #ifdef  USING_DC_MOTORS
     {"mtypes", "report types of motors found", mt_cmd},
 #endif
-    {"s","1-4, filter param", scmd},
+    {"s","1-4, RPM and speed filter param", scmd},
     {"pot", "read drivers control pot", pot_cmd},
     {"fw", "forward", fw_cmd},
     {"re", "reverse", re_cmd},
@@ -485,10 +508,14 @@
     {"vi", "set motors V and I percent RANGE 0 to 100", vi_cmd},
     {"?v", "Report system bus voltage", sysV_report},
     {"?i", "Report motor both currents", sysI_report},
+    {"?w", "show WatchDog timer contents", wd_report},
     {"who", "search for connected units, e.g. 3who returs 'who3' if found", who_cmd},
     {"mode", "read or set params in eeprom", mode19_cmd},                                 //  Big change Jan 2019
+    {"ssl", "set speed limit e.g. 10.7", ssl_cmd},              //  NEW July 2019 ONLY HERE FOR TEST, normal use is from Touch Screen only.
 //    {"erase", "set eeprom contents to all 0xff", erase_cmd},
+#ifdef  TEMP_SENSOR_ENABLE
     {"tem", "report temperature", temperature_cmd},                                     //  Reports -50 when sensor not fitted
+#endif
     {"kd", "kick the dog, reloads WatchDog", kd_cmd},
     {"ver", "Version", ver_cmd},
     {"rcin", "Report Radio Control Input stuff", rcin_pccmd},