Hello @Antun_Skuric and @JorgeMaker !
Sorry for the one month absence, I was on vacation and couldn’t test any codes. I just got back to it today !
Also know that I would not leave this forum without having succeeded and having shared the result of this project to be able to help other people
I tested the codes you sent me and I have several results
First I tested the code for the hall sensors :
#include <PciManager.h>
#include <PciListenerImp.h>
#include <SimpleFOC.h>
// Hall sensor instance
// HallSensor(int hallA, int hallB , int cpr, int index)
// - hallA, hallB, hallC - HallSensor A, B and C pins
// - pp - pole pairs
HallSensor sensor = HallSensor(10, 11, 12, 13);
// Interrupt routine initialization
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// sensor interrupt init
PciListenerImp listenA(sensor.pinA, doA);
PciListenerImp listenB(sensor.pinB, doB);
PciListenerImp listenC(sensor.pinC, doC);
void setup() {
// monitoring port
Serial.begin(115200);
// check if you need internal pullups
sensor.pullup = Pullup::USE_EXTERN;
// initialize sensor hardware
sensor.init();
// interrupt initialization
PciManager.registerListener(&listenA);
PciManager.registerListener(&listenB);
PciManager.registerListener(&listenC);
Serial.println("Sensor ready");
_delay(1000);
}
void loop() {
// display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
}
Thanks to this code I have the angle and the velocity. BUT ! I don’t know what the 13 corresponds to in my hall sensor setup… (I’ve solder the pins to activate the encoders on the back of the card.)
And with this code (which I think is functional) I wrote this code :
#include <PciManager.h>
#include <PciListenerImp.h>
#include <SimpleFOC.h>
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8, 4, 7);
// encoder instance
///Encoder encoder = Encoder(10, 11, 500);
//Hall sensor
HallSensor sensor = HallSensor(10, 11, 12, 13);
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// sensor interrupt init
PciListenerImp listenA(sensor.pinA, doA);
PciListenerImp listenB(sensor.pinB, doB);
PciListenerImp listenC(sensor.pinC, doC);
/*
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
*/
// inline current sensor instance
InlineCurrentSense current_sense = InlineCurrentSense(0.001, 50.0, A0, A1);
// commander communication instance
Commander command = Commander(Serial);
void doMotor(char* cmd){ command.motor(&motor, cmd); }
void setup() {
// monitoring port
Serial.begin(115200);
// check if you need internal pullups
sensor.pullup = Pullup::USE_EXTERN;
// initialize sensor hardware
sensor.init();
// interrupt initialization
PciManager.registerListener(&listenA);
PciManager.registerListener(&listenB);
PciManager.registerListener(&listenC);
Serial.println("Sensor ready");
_delay(1000);
/*
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
*/
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 20;
driver.init();
// link driver
motor.linkDriver(&driver);
motor.voltage_sensor_align = 1;
// set control loop type to be used
motor.torque_controller = TorqueControlType::foc_current;
motor.controller = MotionControlType::torque;
// contoller configuration based on the controll type
motor.PID_velocity.P = 0.05;
motor.PID_velocity.I = 1;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 12;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle loop controller
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 20;
// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
motor.monitor_downsample = 0; // disable intially
motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE; // monitor target velocity and angle
// current sense init and linking
current_sense.init();
motor.linkCurrentSense(¤t_sense);
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the inital target value
motor.target = 0;
// subscribe motor to the commander
command.add('M', doMotor, "motor");
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
Serial.println(F("Motor commands sketch | Initial motion control > torque/current : target 0Amps."));
_delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outter loop target
motor.move();
// motor monitoring
motor.monitor();
// user communication
command.run();
}
… who is not functional.
I mixed the code from single_full_control with the first one. And the board is smoking …
I handed in the code to know the position and it seemed to work. So I don’t know if I burnt out the BTNs or the wheel. But I’m pretty sure this code doesn’t work …
In addition, I would like to remind you that my BTNs come from Aliexpress. So I cannot be sure that they are working well … but I have more of them if needed.
In addition I tested (before seeing smoke) the single_full_control code without any modifications and the engine shuddered slightly. Which leads me to say that only a few small tweaks are missing for it to work, but I don’t know which ones …
I can’t seem to see what I’m missing, can you help me (again) ?
A big thank-you, regards