#include <SimpleFOC.h>
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);
TwoWire Wire1(PB11, PB10);
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(PB1, PB0, PA7, 8);
BLDCMotor motor1 = BLDCMotor(7);
BLDCDriver3PWM driver1 = BLDCDriver3PWM(PB9, PA1, PB8, 8);
float speed = 0.000f;
int xValue = 0;
int yValue = 0;
bool messageStarted = false;
byte receivedBytes[4];
int byteIndex = 0;
HardwareSerial Serial3(PC11, PC10);
void setup() {
// initialise magnetic sensor hardware
sensor.init();
sensor1.init(&Wire1);
// link the motor to the sensor
motor.linkSensor(&sensor1);
motor1.linkSensor(&sensor);
// power supply voltage
driver.voltage_power_supply = 9;
driver.init();
motor.linkDriver(&driver);
driver1.voltage_power_supply = 9;
driver1.init();
motor1.linkDriver(&driver1);
// aligning voltage
motor.voltage_sensor_align = 2;
motor.velocity_index_search = 0.5;
// choose FOC modulation (optional)
motor.foc_modulation = FOCModulationType::SinePWM;
// set motion control loop to be used
motor.controller = MotionControlType::torque;
// aligning voltage
motor1.voltage_sensor_align = 2;
motor.velocity_index_search = 0.5;
// choose FOC modulation (optional)
motor1.foc_modulation = FOCModulationType::SinePWM;
// set motion control loop to be used
motor1.controller = MotionControlType::torque;
// velocity PI controller parameters
motor.PID_velocity.P = 0.2f;
motor.PID_velocity.I = 10;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 9;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 9999;
// velocity low pass filtering
// default 5ms - try different values to see what is the best.
// the lower the less filtered
motor.LPF_velocity.Tf = 0.05f;
// velocity PI controller parameters
motor1.PID_velocity.P = 0.2f;
motor1.PID_velocity.I = 10;
motor1.PID_velocity.D = 0;
// default voltage_power_supply
motor1.voltage_limit = 9;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor1.PID_velocity.output_ramp = 9999;
// velocity low pass filtering
// default 5ms - try different values to see what is the best.
// the lower the less filtered
motor1.LPF_velocity.Tf = 0.05;
// initialize motor
motor.init();
motor1.init();
// align sensor and start FOC
motor.initFOC();
motor1.initFOC();
Serial.begin(115200);
Serial3.begin(115200);
Serial.println(“Setup Done”);
_delay(1000);
}
void loop() {
while (Serial3.available() > 0) {
char receivedChar = Serial3.read();
if (receivedChar == '<') {
// Start of message
byteIndex = 0;
messageStarted = true;
} else if (messageStarted) {
// Store the received byte in the buffer
receivedBytes[byteIndex] = receivedChar;
byteIndex++;
if (byteIndex == 4) {
// End of message; process the data
int highByteX = receivedBytes[0];
int lowByteX = receivedBytes[1];
int highByteY = receivedBytes[2];
int lowByteY = receivedBytes[3];
xValue = (int(highByteX) << 8) | lowByteX;
yValue = (int(highByteY) << 8) | lowByteY;
// Process the received values as needed
// Example: Print them to the Serial Monitor
// Serial.print("X: ");
// Serial.print(xValue);
// Serial.print("\tY: ");
// Serial.println(yValue);
speed = map(yValue, 0, 1023, -9.00f, 9.00f);
Serial.println(speed);
messageStarted = false; // Reset for the next message
}
}
}
motor.loopFOC();
motor1.loopFOC();
motor.move(speed);
motor1.move(speed);
}
this is my code for refference the output ramp function has no effect no matter how much I increase its value, can anyone help me?