Hi Runger,
The board is designed by a maker, I am studying with his board.
He did many cool diy design there.
I re-install the platformio with new packages, using 2.2.3 version dev code, issue is the same, still no debug log output…
Here is my code.
#include <SimpleFOC.h>
#include <Arduino.h>
// Motor instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PB_4, PB_5, PB_0, PB_12);
Encoder encoder = Encoder(PA_8, PA_9, 1000);
// Interrupt routine intialisation
// channel A and B callbacks
void doA()
{ encoder.handleA(); }
void doB()
{ encoder.handleB(); }
void doI()
{ encoder.handleIndex(); }
// current sensor
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A1);
// angle,velocity set point variable
float target_velocity = 0;
float target_angle = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char *cmd)
{ command.scalar(&target_velocity, cmd); }
void doMotor(char* cmd)
{ command.motor(&motor, cmd); }
void setup()
{
// use monitoring with serial
Serial.begin(115200);
SimpleFOCDebug::enable(&Serial);
_delay(100);
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
// link current sense and the driver
// current_sense.linkDriver(&driver);
// initialise magnetic sensor hardware
//current_sense.init();
// link the motor to the sensor
//motor.linkCurrentSense(¤t_sense);
// aligning voltage [V]
motor.voltage_sensor_align = 1.5;
// if you are not using aligning voltage, you can set current limitation
motor.phase_resistance = 0.35; // [Ohm]
//motor.phase_resistance = 3.5; // [Ohm]
// index search velocity [rad/s]
// motor.velocity_index_search = 3;
// motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set motion control loop to be used
//motor.controller = MotionControlType::velocity;
motor.torque_controller = TorqueControlType::voltage;
// motor.controller = MotionControlType::torque;
// set the inital target value
// motor.target = 0.5;
// default voltage_power_supply
// internal res is 0.35 ou maximum current is 2A
// maximum volts is 0.7
// this is used for open loop
// motor.voltage_limit = 0.7;
// maximal velocity of the position control
motor.velocity_limit = 10;
// motor.target = 0.1; // Volts
// contoller configuration
// default parameters in defaults.h
// velocity PI controller parameters
motor.PID_velocity.P = 0.012;
motor.PID_velocity.I = 0.04;
//motor.PID_velocity.D = 0.001;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 1000;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
motor.voltage_limit = 0.8;
motor.current_limit = 0.5; // Amps
// angle P controller
motor.P_angle.P = 23;
motor.P_angle.D = 0.01;
// comment out if not needed
motor.useMonitoring(Serial);
motor.monitor_downsample = 1; // setting sample rate, can up to 100+
motor.monitor_variables = _MON_TARGET | _MON_CURR_Q | _MON_CURR_D | _MON_VEL | _MON_ANGLE;
// invert phase b gain
// current_sense.gain_b *=-1;
// skip alignment
// current_sense.skip_align = true;
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
motor.target = 0.5;
// 订阅电机至commander
command.add('M', doMotor,"motor");
// add target command T
// command.add('T', doTarget, "target_velocity");
Serial.println("Motor ready.");
Serial.println("Set the target using serial terminal:");
_delay(300);
}
void loop()
{
// main FOC algorithm function
// the faster you run this function the better
// Arduino UNO loop ~1kHz
// Bluepill loop ~10kHz
motor.loopFOC();
// Motion control function
// velocity, position or voltage (defined in motor.controller)
// this function can be run at much lower frequency than loopFOC() function
// You can also use motor.move() and set the motor.target in the code
// motor.move(target_velocity);
motor.move();
// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
motor.monitor();
// user communication
command.run();
// test current
//PhaseCurrent_s currents = current_sense.getPhaseCurrents();
//float current_magnitude = current_sense.getDCCurrent();
//Serial.print(currents.a * 1000); // milli Amps
//Serial.print("\t");
//Serial.print(currents.b * 1000); // milli Amps
//Serial.print("\t");
//Serial.print(currents.c * 1000); // milli Amps
//Serial.print("\t");
//Serial.println(current_magnitude * 1000); // milli Amps
//test encoder
//encoder.update();
// display the angle and the angular velocity to the terminal
//Serial.print(encoder.getAngle());
//Serial.print("\t");
//Serial.println(encoder.getVelocity());
}
Here is config file
[env:genericSTM32F103CB]
platform = ststm32
board = genericSTM32F103CB
framework = arduino
upload_protocol = stlink
debug_tool = stlink
upload_flags = -c set CPUTAPID 0x1ba01477
build_flags = -D SIMPLEFOC_STM32_DEBUG
lib_archive = false