Skip to content

Commit 9410e1e

Browse files
committed
FIX too much memory for strings
1 parent a24cbe0 commit 9410e1e

File tree

2 files changed

+53
-57
lines changed

2 files changed

+53
-57
lines changed

arduino_foc_minimal/BLDCMotor.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,27 @@ void BLDCMotor::setPhaseVoltage(float Uq, float angle_el) {
259259
// Ubeta = _cos(angle) * Uq; // cos(angle) * Uq;
260260
Ualpha = -_sin(angle) * Uq; // -sin(angle) * Uq;
261261
Ubeta = _cos(angle) * Uq; // cos(angle) * Uq;
262-
262+
263+
// // determine the segment I, II, III
264+
// if ((angle >= 0) && (angle <= _120_D2R)) {
265+
// // section I
266+
// Ua = Ualpha + _1_SQRT3 * Ubeta;
267+
// Ub = _2_SQRT3 * Ubeta;
268+
// Uc = 0;
269+
270+
// } else if ((angle > _120_D2R) && (angle <= (2 * _120_D2R))) {
271+
// // section III
272+
// Ua = 0;
273+
// Ub = _1_SQRT3 * Ubeta - Ualpha;
274+
// Uc = -_1_SQRT3 * Ubeta - Ualpha;
275+
276+
// } else if ((angle > (2 * _120_D2R)) && (angle <= (3 * _120_D2R))) {
277+
// // section II
278+
// Ua = Ualpha - _1_SQRT3 * Ubeta;
279+
// Ub = 0;
280+
// Uc = - _2_SQRT3 * Ubeta;
281+
// }
282+
263283
// Clarke transform
264284
Ua = Ualpha;
265285
Ub = -0.5 * Ualpha + _SQRT3_2 * Ubeta;
@@ -283,7 +303,14 @@ void BLDCMotor::setPwm(int pinPwm, float U) {
283303
// it can be further optimised
284304
// (example U_max = 6 > U_pwm = 127.5 + 21.25*U)
285305
int U_pwm = 127.5 * (U/U_max + 1);
286-
306+
307+
308+
// float U_max = voltage_power_supply;
309+
// // sets the voltage [0,12V(U_max)] to pwm [0,255]
310+
// // - U_max you can set in header file - default 12V
311+
// // - support for HMBGC controller
312+
// int U_pwm = 255.0 * (float)U / (float)U_max;
313+
287314
// limit the values between 0 and 255
288315
U_pwm = (U_pwm < 0) ? 0 : (U_pwm >= 255) ? 255 : U_pwm;
289316

arduino_foc_minimal/arduino_foc_minimal.ino

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
#include "SimpleFOC.h"
2-
// software interrupt library
3-
#include <PciManager.h>
4-
#include <PciListenerImp.h>
2+
// // software interrupt library
3+
// #include <PciManager.h>
4+
// #include <PciListenerImp.h>
55

66
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
77
// - phA, phB, phC - motor A,B,C phase pwm pins
88
// - pp - pole pair number
99
// - enable pin - (optional input)
1010
BLDCMotor motor = BLDCMotor(9, 10, 11, 11);
1111

12-
// MagneticSensor(int cs, float _cpr, int _angle_register)
13-
// cs - SPI chip select pin
14-
// _cpr - counts per revolution
15-
// _angle_register - (optional) angle read register - default 0x3FFF
16-
MagneticSensor AS5x4x = MagneticSensor(10, 16384, 0x3FFF);
17-
18-
19-
// Encoder encoder = Encoder(2, 3, 8192);
20-
// // interrupt ruotine intialisation
12+
//Encoder sensor = Encoder(2, 3, 2048);
13+
// interrupt ruotine intialisation
2114
// void doA(){encoder.handleA();}
2215
// void doB(){encoder.handleB();}
2316

24-
// // encoder interrupt init
17+
// encoder interrupt init
2518
// PciListenerImp listenerA(encoder.pinA, doA);
2619
// PciListenerImp listenerB(encoder.pinB, doB);
2720

21+
22+
MagneticSensor sensor = MagneticSensor(10,16384);
23+
2824
void setup() {
2925
// debugging port
3026
Serial.begin(115200);
3127

28+
//as5047.init();
29+
3230
// initialise magnetic sensor hardware
33-
AS5x4x.init();
34-
// encoder.init();
35-
// encoder.enableInterrupts(doA,doB);
31+
sensor.init();
32+
//encoder.enableInterrupts(doA,doB);
3633

3734
// // interrupt intitialisation
3835
// PciManager.registerListener(&listenerA);
@@ -69,8 +66,9 @@ void setup() {
6966

7067

7168
// link the motor to the sensor
72-
motor.linkSensor(&AS5x4x);
73-
// motor.linkSensor(&encoder);
69+
motor.linkSensor(&sensor);
70+
// motor.linkSensor(&as5047);
71+
7472

7573
// use debugging with serial for motor init
7674
// comment out if not needed
@@ -81,15 +79,15 @@ void setup() {
8179
// align encoder and start FOC
8280
motor.initFOC();
8381

84-
Serial.println("Motor ready.\n");
85-
Serial.println("Update all the PI controller parameters from the serial terminal:");
86-
Serial.println("- Type P100.2 to you the PI_velocity.P in 100.2");
87-
Serial.println("- Type I72.32 to you the PI_velocity.I in 72.32\n");
88-
Serial.println("Update the time constant of the velocity filter:");
89-
Serial.println("- Type F0.03 to you the LPF_velocity.Tf in 0.03\n");
90-
Serial.println("Check the loop execution time (average):");
82+
Serial.println("\n\n");
83+
Serial.println("PI controller parameters change:");
84+
Serial.println("- P value : Prefix P (ex. P0.1)");
85+
Serial.println("- I value : Prefix I (ex. I0.1)\n");
86+
Serial.println("Velocity filter:");
87+
Serial.println("- Tf value : Prefix F (ex. F0.001)\n");
88+
Serial.println("Average loop execution time:");
9189
Serial.println("- Type T\n");
92-
Serial.println("Change control loop type by typing:");
90+
Serial.println("Control loop type:");
9391
Serial.println("- C0 - angle control");
9492
Serial.println("- C1 - velocity control");
9593
Serial.println("- C2 - voltage control\n");
@@ -102,7 +100,6 @@ void setup() {
102100
Serial.println(motor.LPF_velocity.Tf,4);
103101

104102
_delay(1000);
105-
106103
}
107104

108105
// target velocity variable
@@ -123,34 +120,6 @@ void loop() {
123120
t++;
124121
}
125122

126-
// utility function intended to be used with serial plotter to monitor motor variables
127-
// significantly slowing the execution down!!!!
128-
void motor_monitor() {
129-
switch (motor.controller) {
130-
case ControlType::velocity:
131-
Serial.print(motor.voltage_q);
132-
Serial.print("\t");
133-
Serial.print(motor.shaft_velocity_sp);
134-
Serial.print("\t");
135-
Serial.println(motor.shaft_velocity);
136-
break;
137-
case ControlType::angle:
138-
Serial.print(motor.voltage_q);
139-
Serial.print("\t");
140-
Serial.print(motor.shaft_angle_sp);
141-
Serial.print("\t");
142-
Serial.println(motor.shaft_angle);
143-
break;
144-
case ControlType::voltage:
145-
Serial.print(motor.voltage_q);
146-
Serial.print("\t");
147-
Serial.print(motor.shaft_angle);
148-
Serial.print("\t");
149-
Serial.println(motor.shaft_velocity);
150-
break;
151-
}
152-
}
153-
154123
// Serial communication callback
155124
void serialEvent() {
156125
// a string to hold incoming data

0 commit comments

Comments
 (0)