Skip to content

Commit 98712b6

Browse files
committed
added monitoring control through commands + motion loop downsampling
1 parent bba4ab4 commit 98712b6

File tree

9 files changed

+239
-144
lines changed

9 files changed

+239
-144
lines changed

src/BLDCMotor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ void BLDCMotor::loopFOC() {
289289
void BLDCMotor::move(float new_target) {
290290
// if disabled do nothing
291291
if(!enabled) return;
292+
// downsampling (optional)
293+
if(motion_cnt++ < motion_downsample) return;
294+
motion_cnt = 0;
292295
// set internal target variable
293296
if(_isset(new_target)) target = new_target;
294297
// get angular velocity

src/StepperMotor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ void StepperMotor::loopFOC() {
178178
void StepperMotor::move(float new_target) {
179179
// if disabled do nothing
180180
if(!enabled) return;
181+
// downsampling (optional)
182+
if(motion_cnt++ < motion_downsample) return;
181183
// set internal target variable
182184
if(_isset(new_target) ) target = new_target;
183185
// get angular velocity

src/common/base_classes/CommunicationNode.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/common/base_classes/FOCMotor.cpp

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,46 @@ void FOCMotor::useMonitoring(Print &print){
8181
// utility function intended to be used with serial plotter to monitor motor variables
8282
// significantly slowing the execution down!!!!
8383
void FOCMotor::monitor() {
84+
if( !monitor_downsample || monitor_cnt++ < monitor_downsample ) return;
85+
monitor_cnt = 0;
8486
if(!monitor_port) return;
85-
switch (controller) {
86-
case MotionControlType::velocity_openloop:
87-
case MotionControlType::velocity:
88-
monitor_port->print(voltage.q);
89-
monitor_port->print("\t");
90-
monitor_port->print(shaft_velocity_sp);
91-
monitor_port->print("\t");
92-
monitor_port->println(shaft_velocity);
93-
break;
94-
case MotionControlType::angle_openloop:
95-
case MotionControlType::angle:
96-
monitor_port->print(voltage.q);
97-
monitor_port->print("\t");
98-
monitor_port->print(shaft_angle_sp);
99-
monitor_port->print("\t");
100-
monitor_port->println(shaft_angle);
101-
break;
102-
case MotionControlType::torque:
103-
monitor_port->print(voltage.q);
104-
monitor_port->print("\t");
105-
monitor_port->print(shaft_angle);
106-
monitor_port->print("\t");
107-
monitor_port->println(shaft_velocity);
108-
break;
87+
bool printed = 0;
88+
89+
if(monitor_variables[0]){
90+
monitor_port->print(target);
91+
monitor_port->print("\t");
92+
printed= true;
93+
}
94+
if(monitor_variables[1]) {
95+
monitor_port->print(voltage.q);
96+
monitor_port->print("\t");
97+
printed= true;
98+
}
99+
if(monitor_variables[2]) {
100+
monitor_port->print(voltage.d);
101+
monitor_port->print("\t");
102+
printed= true;
103+
}
104+
if(monitor_variables[3]) {
105+
monitor_port->print(current.q*1000); // mAmps
106+
monitor_port->print("\t");
107+
printed= true;
109108
}
109+
if(monitor_variables[4]) {
110+
monitor_port->print(current.d*1000); // mAmps
111+
monitor_port->print("\t");
112+
printed= true;
113+
}
114+
if(monitor_variables[5]) {
115+
monitor_port->print(shaft_velocity);
116+
monitor_port->print("\t");
117+
printed= true;
118+
}
119+
if(monitor_variables[6]) {
120+
monitor_port->print(shaft_angle);
121+
printed= true;
122+
}
123+
if(printed) monitor_port->println();
124+
110125
}
111126

src/common/base_classes/FOCMotor.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ class FOCMotor
142142
float velocity_limit; //!< Velocity limitting variable - global limit
143143

144144
// motor status vairables
145-
int enabled = 0;//!< enabled or disabled motor flag
145+
int8_t enabled = 0;//!< enabled or disabled motor flag
146146

147147
// pwm modulation related variables
148148
FOCModulationType foc_modulation;//!< parameter derterniming modulation algorithm
149-
int modulation_centered = 1;//!< flag (1) centered modulation around driver limit /2 or (0) pulled to 0
149+
int8_t modulation_centered = 1;//!< flag (1) centered modulation around driver limit /2 or (0) pulled to 0
150150

151151

152152
// configuration structures
@@ -162,6 +162,8 @@ class FOCMotor
162162
PIDController P_angle{DEF_P_ANGLE_P,0,0,1e10,DEF_VEL_LIM}; //!< parameter determining the position PID configuration
163163
LowPassFilter LPF_velocity{DEF_VEL_FILTER_Tf};//!< parameter determining the velocity Low pass filter configuration
164164
LowPassFilter LPF_angle{0.0};//!< parameter determining the angle low pass filter configuration
165+
unsigned int motion_downsample = 0; //!< parameter defining the ratio of downsampling for move commad
166+
unsigned int motion_cnt = 0; //!< counting variable for downsampling for move commad
165167

166168
// sensor related variabels
167169
float sensor_offset; //!< user defined sensor zero offset
@@ -181,6 +183,9 @@ class FOCMotor
181183
* significantly slowing the execution down!!!!
182184
*/
183185
void monitor();
186+
unsigned int monitor_cnt = 0 ;
187+
unsigned int monitor_downsample = 1;
188+
bool monitor_variables[7] = {0};
184189

185190
/**
186191
* Sensor link:

src/common/defaults.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define DEF_PID_CURR_D 0.0 //!< default PID controller D value
2626
#define DEF_PID_CURR_RAMP 1e11 //!< default PID controller voltage ramp value
2727
#define DEF_PID_CURR_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit
28-
#define DEF_CURR_FILTER_Tf 0.001 //!< default currnet filter time constant
28+
#define DEF_CURR_FILTER_Tf 0.002 //!< default currnet filter time constant
2929
#endif
3030
// default current limit values
3131
#define DEF_CURRENT_LIM 0.2 //!< 2Amps current limit by default

0 commit comments

Comments
 (0)