Hi everybody, I am using two FOC Sheilds stacked on Nucleo 64 G431RB. Problem is both sheilds work individually with their respective motor, But when i stacked them, one of them stop working. Even when i enter angle for First motor it goes that position but somehow motor 1 also rotates a little bit.
#include <SimpleFOC.h>
// Motor 1 Big
// Motor 2 Small
BLDCMotor motor1 = BLDCMotor(2);
BLDCDriver3PWM driver1 = BLDCDriver3PWM(5, 10, 6, 8);
BLDCMotor motor2 = BLDCMotor(4);
BLDCDriver3PWM driver2 = BLDCDriver3PWM(3, 9, 13, 7);
//target variable
float target_position_1 = 0;
float target_position_2 = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget1(char* cmd) { command.scalar(&target_position_1, cmd); }
void doLimit1(char* cmd) { command.scalar(&motor1.voltage_limit, cmd); }
void doVelocity1(char* cmd) { command.scalar(&motor1.velocity_limit, cmd); }
void doTarget2(char* cmd) { command.scalar(&target_position_2, cmd); }
void doLimit2(char* cmd) { command.scalar(&motor2.voltage_limit, cmd); }
void doVelocity2(char* cmd) { command.scalar(&motor2.velocity_limit, cmd); }
void setup() {
// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);
// driver config
// power supply voltage [V]
driver1.voltage_power_supply = 12;
driver2.voltage_power_supply = 12;
// this value is fixed on startup
driver1.voltage_limit = 6;
driver2.voltage_limit = 6;
if(!driver1.init()){
Serial.println("Driver 1 init failed!");
return;
}
if(!driver2.init()){
Serial.println("Driver 2 init failed!");
return;
}
// link the motor and the driver
motor1.linkDriver(&driver1);
motor2.linkDriver(&driver2);
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// currnet = resistance*voltage, so try to be well under 1Amp
motor1.voltage_limit = 1; // [V]
motor2.voltage_limit = 2;
// limit/set the velocity of the transition in between
// target angles
motor1.velocity_limit = 30; // [rad/s] cca 50rpm
motor2.velocity_limit = 30; // [rad/s] cca 50rpm
// open loop control config
motor1.controller = MotionControlType::angle_openloop;
motor2.controller = MotionControlType::angle_openloop;
// init motor hardware
if(!motor1.init()){
Serial.println("Motor 1 init failed!");
return;
}
if(!motor2.init()){
Serial.println("Motor 2 init failed!");
return;
}
// add target command T
command.add('T', doTarget1, "target angle");
command.add('L', doLimit1, "voltage limit");
command.add('V', doLimit1, "movement velocity");
command.add('t', doTarget2, "target angle");
command.add('l', doLimit2, "voltage limit");
command.add('v', doLimit2, "movement velocity");
Serial.println("Motor 1 ready!");
Serial.println("Set target position [rad]");
Serial.println("Motor 2 ready!");
Serial.println("Set target position [rad]");
_delay(1000);
}
void loop() {
motor1.move(target_position_1);
motor2.move(target_position_2);
command.run();
}