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 204:74714d52a936, committed 2018-02-12
- Comitter:
- bwang
- Date:
- Mon Feb 12 04:12:07 2018 +0000
- Parent:
- 203:cb2a3ea31dce
- Child:
- 205:5cfe6d7e08a3
- Commit message:
- 02/11/2018 21:11 - further improvements to mode handling, output overrides and output disabling now live in their own functions
Changed in this revision
--- a/CHANGELOG.txt Mon Feb 12 03:41:12 2018 +0000 +++ b/CHANGELOG.txt Mon Feb 12 04:12:07 2018 +0000 @@ -42,6 +42,7 @@ 02/10/2018 01:35 - can now switch command source to terminal, added 'clear' command (which clears the screen on POSIX-compliant terminals) 02/10/2018 17:00 - fixed a bug in BREMSConfig where the delay was in the wrong spot 02/11/2018 02:11 - added BREMS_mode. most modes are stubs right now (BREMS_CFG does a rudimentary encoder zero-ing, BREMS_CFG disables outputs) -02/11/2017 02:54 - long commands can no longer be executed while control.enabled == true, invalid BREMS_src now sets control.user_cmd to 0 -02/11/2017 03:16 - blocked switching modes when motor is running -02/11/2017 20:13 - scrambled the mode and error handling code in commutate() to be cleaner \ No newline at end of file +02/11/2018 02:54 - long commands can no longer be executed while control.enabled == true, invalid BREMS_src now sets control.user_cmd to 0 +02/11/2018 03:16 - blocked switching modes when motor is running +02/11/2018 20:13 - scrambled the mode and error handling code in commutate() to be cleaner +02/11/2018 21:11 - further improvements to mode handling, output overrides and output disabling now live in their own functions \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Transforms/modes.cpp Mon Feb 12 04:12:07 2018 +0000
@@ -0,0 +1,27 @@
+#include "prefs.h"
+
+bool mode_enables_logging() {
+ switch(BREMS_mode) {
+ case MODE_RUN:
+ return true;
+ case MODE_CFG:
+ case MODE_ZERO:
+ case MODE_CHR:
+ return false;
+ default:
+ return false;
+ }
+}
+
+bool mode_enables_output() {
+ switch(BREMS_mode) {
+ case MODE_RUN:
+ case MODE_ZERO:
+ case MODE_CHR:
+ return true;
+ case MODE_CFG:
+ return false;
+ default:
+ return false;
+ }
+}
\ No newline at end of file
--- a/errors.cpp Mon Feb 12 03:41:12 2018 +0000
+++ b/errors.cpp Mon Feb 12 04:12:07 2018 +0000
@@ -35,32 +35,6 @@
return control.torque_percent > 0.01f || fabsf(read.w) > _W_SAFE;
}
-bool mode_enables_logging() {
- switch(BREMS_mode) {
- case MODE_RUN:
- return true;
- case MODE_CFG:
- case MODE_ZERO:
- case MODE_CHR:
- return false;
- default:
- return false;
- }
-}
-
-bool mode_enables_output() {
- switch(BREMS_mode) {
- case MODE_RUN:
- case MODE_ZERO:
- case MODE_CHR:
- return true;
- case MODE_CFG:
- return false;
- default:
- return false;
- }
-}
-
#define _seterr(x) errors |= (1 << x)
#define _unseterr(x) errors &= ~(1 << x)
#define _upderr(x) _unseterr(x) : _seterr(x)
--- a/main.cpp Mon Feb 12 03:41:12 2018 +0000
+++ b/main.cpp Mon Feb 12 04:12:07 2018 +0000
@@ -87,6 +87,16 @@
/*set outputs*/
float va, vb, vc, voff;
+
+ invclarke(foc.valpha, foc.vbeta, &va, &vb);
+ vc = -va - vb;
+
+ /*SVPWM*/
+ voff = (fminf(va, fminf(vb, vc)) + fmaxf(va, fmaxf(vb, vc)))/2.0f;//don't think about it
+ va = va - voff;
+ vb = vb - voff;
+ vc = vc - voff;
+
switch (BREMS_mode) {
case MODE_CFG:
va = 0.0f;
@@ -94,13 +104,6 @@
vc = 0.0f;
break;
case MODE_RUN:
- invclarke(foc.valpha, foc.vbeta, &va, &vb);
- vc = -va - vb;
- /*SVPWM*/
- voff = (fminf(va, fminf(vb, vc)) + fmaxf(va, fmaxf(vb, vc)))/2.0f;//don't think about it
- va = va - voff;
- vb = vb - voff;
- vc = vc - voff;
break;
case MODE_ZERO:
va = 0.9f;
@@ -113,27 +116,12 @@
}
/*safety checks, reset integral*/
- if (!checks_passed()) {
- /*do this even in disabled state, to keep integral down*/
- go_disabled();
- }
-
- /*some modes disable output*/
- switch (BREMS_mode) {
- case MODE_CFG:
+ if (!checks_passed() || !mode_enables_output()) {
go_disabled();
- break;
- case MODE_RUN:
- case MODE_ZERO:
- case MODE_CHR:
- break;
- default:
- go_disabled();
- break;
}
/*log data*/
- if (_ENABLE_LOGGING) log();
+ if (_ENABLE_LOGGING && mode_enables_logging()) log();
/*disable outputs if necessary*/
if (!control.enabled) {
@@ -171,19 +159,6 @@
}
void log() {
- switch (BREMS_mode) {
- case MODE_RUN:
- send_packet();
- break;
- case MODE_CFG:
- case MODE_ZERO:
- case MODE_CHR:
- default:
- break;
- }
-}
-
-void send_packet() {
float packet[8];
packet[0] = read.w / 8.0f;
packet[1] = control.d_ref / 2.0f + 128.0f;
--- a/main.h Mon Feb 12 03:41:12 2018 +0000 +++ b/main.h Mon Feb 12 04:12:07 2018 +0000 @@ -15,5 +15,4 @@ void update_velocity(); void log(); -void send_packet(); void rxCallback(); \ No newline at end of file