epfl-cs358 / 2024sp-robopong

2 stars 0 forks source link

Making the power supply working #56

Closed cemuelle closed 4 months ago

cemuelle commented 4 months ago

Power the whole system with our power supply. Now there is an issue that when initializing the motors, they draw to much current and it cannot complete the setup.

cemuelle commented 4 months ago

To managed to power with our power supply the whole game board, I had to make some changes :

#include <Arduino.h>
#include <SimpleFOC.h>

BLDCMotor motor = BLDCMotor(7, 0.025); // br3536 kv1200
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f/7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

Commander commander = Commander(Serial);
void onMotion(char* cmd) { commander.motion(&motor, cmd); }

void setup() {
  delay(2000);
  Wire.setClock(400000);
  sensor.init();

  motor.linkSensor(&sensor);

  driver.voltage_power_supply = 12;
  driver.init();
  motor.linkDriver(&driver);
  currentSense.linkDriver(&driver);

  currentSense.init();
  currentSense.skip_align = true;
  motor.linkCurrentSense(&currentSense);

  motor.controller = MotionControlType::angle;

  motor.voltage_limit = 12;
  motor.current_limit = 35;
  motor.velocity_limit = 200;

  motor.PID_velocity.P = 0.2;
  motor.PID_velocity.I = 20;
  motor.PID_velocity.D = 0.001;
  motor.PID_velocity.output_ramp = 2000;
  motor.LPF_velocity.Tf = 0.01;

  Serial.begin(115200);

  motor.useMonitoring(Serial);

  motor.sensor_direction = Direction::CW;

  motor.sensor_offset = 0;
  motor.voltage_sensor_align = 6;

  motor.init();
  motor.initFOC();

  commander.add('M', onMotion, "motion control");

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target angle using serial terminal:"));
  _delay(1000);
}

void loop() {
  motor.loopFOC();
  motor.move();
  commander.run();
}
cemuelle commented 4 months ago

Before these modifications, the motors weren't able to complete they're initialization and the screen of the board was going off. Now we saw that the screen blink a little bit, but still receive current !

https://github.com/epfl-cs358/2024sp-robopong/assets/55513917/2c86bed8-51ab-4718-a81a-296f8024ca99