File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class MotorDriver : public ChoosableClass{
2727 const ClassType getClassType () override {return ClassType::Motordriver;};
2828 static const std::vector<class_entry<MotorDriver>> all_drivers;
2929
30+ virtual void setupDriver ();
3031 virtual void turn (int16_t power);
3132 virtual void stopMotor ();
3233 virtual void startMotor ();
Original file line number Diff line number Diff line change @@ -430,7 +430,7 @@ void Axis::setDrvType(uint8_t drvtype)
430430 return ;
431431 }
432432 cpp_freertos::CriticalSection::Enter ();
433- this ->drv .reset (drv_chooser .Create ((uint16_t )drvtype));
433+ this ->drv .reset (driverChooser .Create ((uint16_t )drvtype));
434434 if (drv == nullptr )
435435 {
436436 cpp_freertos::CriticalSection::Exit ();
@@ -443,6 +443,9 @@ void Axis::setDrvType(uint8_t drvtype)
443443 if (!this ->drv ->hasIntegratedEncoder ()){
444444 this ->drv ->setEncoder (this ->enc );
445445 }
446+
447+ drv->setupDriver ();
448+
446449 if (!tud_connected ())
447450 {
448451 control->usb_disabled = false ;
Original file line number Diff line number Diff line change @@ -81,6 +81,12 @@ const ClassIdentifier MotorDriver::getInfo(){
8181 return info;
8282}
8383
84+ /* *
85+ * Setup driver when is selected
86+ */
87+ void MotorDriver::setupDriver (){
88+
89+ }
8490
8591/* *
8692 * Turn the motor with positive/negative power.
Original file line number Diff line number Diff line change @@ -424,6 +424,7 @@ friend class TMCDebugBridge;
424424
425425 TMC4671MainConfig conf;
426426
427+ void setupDriver ();
427428 bool initialize ();
428429 void initializeWithPower ();
429430
@@ -503,6 +504,7 @@ friend class TMCDebugBridge;
503504 bool emergency = false ;
504505 bool estopTriggered = false ;
505506 void turn (int16_t power);
507+
506508 int16_t getVelocityControllerTorque ();
507509 int16_t nextFlux = 0 ;
508510 int16_t idleFlux = 0 ;
Original file line number Diff line number Diff line change @@ -240,6 +240,18 @@ int32_t TMC4671::getTmcVM(){
240240 return ((float )agpiA_VM * conf.hwconf .vmScaler ) * 1000 ;
241241}
242242
243+ void TMC4671::setupDriver () {
244+ // Configuration specific to TMC4671 upon starting the motor
245+ // The power limit is set by the Axis class via setPowerLimit during initialization.
246+
247+ this ->setExternalEncoderAllowed (true );
248+ this ->restoreFlash ();
249+ this ->setLimits (curLimits);
250+
251+ // Start driver
252+ this ->setMotionMode (MotionMode::torque);
253+ this ->Start (); // Start thread
254+ }
243255
244256/* *
245257 * Sets all parameters of the driver at startup. Only has to be called once when the driver is detected
@@ -1675,13 +1687,6 @@ void TMC4671::startMotor(){
16751687 }
16761688 // Start driver if powered and emergency flag reset
16771689 if (hasPower () && !emergency){
1678- // Configuration specific to TMC4671 upon starting the motor
1679- // The power limit is set by the Axis class via setPowerLimit during initialization.
1680- // We call setLimits() here to ensure all other limits (velocity, acceleration, etc.) are applied from the defaults.
1681- setExternalEncoderAllowed (true );
1682- setLimits (curLimits);
1683- setMotionMode (MotionMode::torque);
1684-
16851690 setPwm (TMC_PwmMode::PWM_FOC); // enable foc
16861691 enablePin.set ();
16871692 setMotionMode (nextMotionMode,true );
You can’t perform that action at this time.
0 commit comments