1- // UNCOMMENTED CODE REQUIRES DEBUGGING AND IS CURRENTLY ON PAUSE DUE TO POWER DISTRIBUTION ISSUES ON MOTOR CONTROLLER HUB
1+ // UNCOMMENTED CODE REQUIRES DEBUGGING AND IS CURRENTLY ON PAUSE DUE TO POWER
2+ // DISTRIBUTION ISSUES ON MOTOR CONTROLLER HUB
23
34// #include <SimpleFOC.h>
45// #include <Wire.h>
1516// BLDCMotor motor = BLDCMotor(7);
1617// BLDCMotor motor2 = BLDCMotor(7);
1718
18- // // BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
19+ // // BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC,
20+ // Enable(optional));
1921// // BLDCDriver3PWM driver = BLDCDriver3PWM(33,32,25,12);
2022// BLDCDriver3PWM driver = BLDCDriver3PWM(7,8,9);
2123// BLDCDriver3PWM driver2 = BLDCDriver3PWM(1,2,3);
2224
23- // //TO RE-FLASH ESP32-S3: esptool.py --chip esp32s3 --port /dev/ttyACM0 erase_flash
24-
25+ // //TO RE-FLASH ESP32-S3: esptool.py --chip esp32s3 --port /dev/ttyACM0
26+ // erase_flash
2527
2628// MagneticSensorI2C magnetic_encoder = MagneticSensorI2C(AS5600_I2C);
2729
28-
2930// // Stepper motor & driver instance
3031
31-
32-
3332// //target variable
3433// float target_velocity = 0;
3534// float target_angle = 0;
3635
3736// // instantiate the commander
3837// Commander command = Commander(Serial);
39- // void doTarget(char* cmd) {
38+ // void doTarget(char* cmd) {
4039// // command.scalar(&target_velocity, cmd);
41- // // motor.controller = MotionControlType::velocity_openloop;
40+ // // motor.controller = MotionControlType::velocity_openloop;
4241// target_velocity = target_velocity;
4342// }
4443// void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
4948// // target_velocity = target_angle;
5049// }
5150
52-
53-
54-
5551// void setup() {
5652
57- // // use monitoring with serial
53+ // // use monitoring with serial
5854// Serial.begin(115200);
5955// WiFi.mode(WIFI_STA);
6056// WiFi.setHostname("ESP32-BLDC");
6157
6258// WiFi.begin(ssid, password);
6359
64-
65-
6660// while (WiFi.status() != WL_CONNECTED) {
6761// delay(100);
6862// Serial.println("CONNECTING");
7367// String type;
7468// if (ArduinoOTA.getCommand() == U_FLASH) {
7569// type = "sketch";
76- // } else {
70+ // } else {
7771
7872// type = "filesystem";
7973// }
8579// Serial.print("IP address: ");
8680// Serial.println(WiFi.localIP());
8781
88-
89-
9082// motor.useMonitoring(Serial);
91-
83+
9284// motor2.useMonitoring(Serial);
9385
94-
9586// // Serial.println("CHECKING FOR ADDRESS");
9687
9788// // for (byte i=0;i<127;i++) {
10192// // }
10293// // }
10394
104-
10595// motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE;
106- // motor2.monitor_variables = _MON_TARGET | _MON_VEL | _MON_VOLT_D | _MON_VOLT_Q | _MON_CURR_D;
107-
96+ // motor2.monitor_variables = _MON_TARGET | _MON_VEL | _MON_VOLT_D |
97+ // _MON_VOLT_Q | _MON_CURR_D;
10898
10999// // enable more verbose output for debugging
110100// // comment out if not needed
130120// motor.linkDriver(&driver);
131121// motor.linkSensor(&magnetic_encoder);
132122
133-
134123// motor2.linkDriver(&driver2);
135124
136125// //motor.linkSensor(&magnetic_encoder);
140129// // current = voltage / resistance, so try to be well under 1Amp
141130// motor.voltage_limit = 4; // [V]
142131// motor.current_limit = 0.2;
143-
132+
144133// // open loop control config
145134// motor.controller = MotionControlType::velocity_openloop;
146135
147136// motor2.voltage_limit = 4; // [V]
148137// motor2.current_limit = 0.2;
149-
150138
151139// //motor.initFOC();
152-
153140
154141// // open loop control config
155142// motor2.controller = MotionControlType::velocity_openloop;
159146// Serial.println("Motor init failed!");
160147// return;
161148// }
162-
163149
164150// // add target command T
165151// command.add('T', doTarget, "target velocity");
166152// command.add('L', doLimit, "voltage limit");
167153// command.add('M',doMotor,"motor");
168154// command.add('A',doAngleTarget,"angle");
169155
170-
171156// Serial.println("Motor ready!");
172157
173-
174158// Serial.println("Set target velocity [rad/s]");
175159
176-
177160// // Serial.println(motor.enabled);
178161// }
179162
180163// void loop() {
181164
182-
183165// // open loop velocity movement
184166// // using motor.voltage_limit and motor.velocity_limit
185167// // to turn the motor "backwards", just set a negative target_velocity
186168
187-
188-
189169// // Serial.println("AAA");
190-
170+
191171// //analogWrite(26, 128); // 50% duty cycle (speed control)
192172// // delay(5000); // Run for 5 seconds
193173
205185
206186// //Serial.println(magnetic_encoder.getVelocity());
207187
208-
209188// // analogWrite(26, 0); // Stop the motor
210189// // delay(5000); // Wait 5 seconds
211190
217196// Open loop motor control example
218197#include < SimpleFOC.h>
219198
220-
221199// BLDC motor & driver instance
222200// BLDCMotor motor = BLDCMotor(pole pair number);
223201BLDCMotor motor = BLDCMotor(7 );
224202// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
225- BLDCDriver3PWM driver = BLDCDriver3PWM(8 ,9 , 7 );
203+ BLDCDriver3PWM driver = BLDCDriver3PWM(8 , 9 , 7 );
226204
227205// Stepper motor & driver instance
228- // StepperMotor motor = StepperMotor(50);
229- // StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
230-
206+ // StepperMotor motor = StepperMotor(50);
207+ // StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
231208
232- // target variable
209+ // target variable
233210float target_velocity = 1 ;
234211
235212// instantiate the commander
236213Commander command = Commander(Serial);
237- void doTarget (char * cmd) { command.scalar (&target_velocity, cmd); }
238- void doLimit (char * cmd) { command.scalar (&motor.voltage_limit , cmd); }
214+ void doTarget (char * cmd) { command.scalar (&target_velocity, cmd); }
215+ void doLimit (char * cmd) { command.scalar (&motor.voltage_limit , cmd); }
239216
240217void setup () {
241218
242- // use monitoring with serial
219+ // use monitoring with serial
243220 Serial.begin (115200 );
244221 // enable more verbose output for debugging
245222 // comment out if not needed
@@ -252,7 +229,7 @@ void setup() {
252229 // as a protection measure for the low-resistance motors
253230 // this value is fixed on startup
254231 driver.voltage_limit = 6 ;
255- if (!driver.init ()){
232+ if (!driver.init ()) {
256233 Serial.println (" Driver init failed!" );
257234 return ;
258235 }
@@ -263,13 +240,13 @@ void setup() {
263240 // limit the voltage to be set to the motor
264241 // start very low for high resistance motors
265242 // current = voltage / resistance, so try to be well under 1Amp
266- motor.voltage_limit = 3 ; // [V]
267-
243+ motor.voltage_limit = 3 ; // [V]
244+
268245 // open loop control config
269246 motor.controller = MotionControlType::velocity_openloop;
270247
271248 // init motor hardware
272- if (!motor.init ()){
249+ if (!motor.init ()) {
273250 Serial.println (" Motor init failed!" );
274251 return ;
275252 }
@@ -293,5 +270,3 @@ void loop() {
293270 // user communication
294271 command.run ();
295272}
296-
297-
0 commit comments