I could not set motor.motion_downsample. It is always zero (the default value) regardless how I set it in the setup(). I tried to put motor.motion_downsample = 2;
before motor.init()
before motor.initFOC()
after motor.initFOC()
in loop()
All failed. But I was able to set motor.monitor_downsample. Could someone help?
My setup
- MCU: Arduino Mega
- Driver: Simplefoc Shield V2.0.4
- Motor: T-motor gimbal motor
- Sensor: AS5047P
- Programming env: Arduino IDE
- Power supply: 3S Lipo
Code
#include <SimpleFOC.h>
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 53);
BLDCMotor motor = BLDCMotor(7, 14.4);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
Commander commander = Commander(Serial);
void onMotor(char* cmd){ commander.motor(&motor,cmd); }
void setup() {
Serial.begin(115200);
SimpleFOCDebug::enable(&Serial);
sensor.init();
motor.linkSensor(&sensor);
driver.voltage_power_supply = 11.5;
driver.init();
motor.linkDriver(&driver);
motor.voltage_sensor_align = 2;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::torque;
motor.target = 0;
motor.useMonitoring(Serial);
motor.monitor_downsample = 120;
motor.motion_downsample = 2;
motor.init();
// motor.motion_downsample = 2;
motor.initFOC();
// motor.motion_downsample = 2;
commander.add('M',onMotor,"my motor motion");
Serial.println(F("Motor ready."));
Serial.println(F("Set the target voltage using serial terminal:"));
_delay(1000);
}
void loop() {
// motor.motion_downsample = 2;
motor.loopFOC();
motor.move();
commander.run();
}
Serial monitor output