22 * MotorDriver.h
33 *
44 * Created on: Feb 1, 2020
5- * Author: Yannick
5+ * Author: Yannick, Vincent
66 */
77
88#ifndef MOTORDRIVER_H_
99#define MOTORDRIVER_H_
1010
11+ #define MAX_SLEW_RATE 65535
12+
1113#include " cppmain.h"
1214#include " ChoosableClass.h"
1315#include " PersistentStorage.h"
1416#include " Encoder.h"
1517#include " memory"
1618
17- #define MAX_SLEW_RATE 65535
18-
1919class Encoder ;
20-
21- /* *
22- * @brief Base class for all motor drivers.
23- * This class defines the interface for controlling a motor and optionally its integrated encoder.
24- */
2520class MotorDriver : public ChoosableClass {
2621public:
2722 MotorDriver (){};
@@ -32,75 +27,46 @@ class MotorDriver : public ChoosableClass{
3227 const ClassType getClassType () override {return ClassType::Motordriver;};
3328 static const std::vector<class_entry<MotorDriver>> all_drivers;
3429
35- /* *
36- * @brief Sends a torque command to the motor.
37- * @param power The torque value (signed 16-bit).
38- */
30+ virtual void setupDriver ();
3931 virtual void turn (int16_t power);
40- /* *
41- * @brief Stops the motor (torque = 0).
42- */
4332 virtual void stopMotor ();
44- /* *
45- * @brief Starts the motor driver.
46- */
4733 virtual void startMotor ();
48- /* *
49- * @brief Triggers an emergency stop.
50- * @param reset If true, resets the driver after stopping.
51- */
5234 virtual void emergencyStop (bool reset = false );
5335
36+ virtual void setPowerLimit (uint16_t power){}; // specific motor driver manager power, this is used to send powerLimit to the driver, like TMC4671.
37+
38+ //
5439 /* *
55- * @brief Checks if the driver is ready to receive torque commands.
56- * @return true if ready, false otherwise.
40+ * Slew rate calibration interface (no-op by default)
41+ * If driver can't calibration the max slew rate will by MAX_SLEW_RATE (65535)
42+ * @return false is the driver not implemented this process or true if calibration start
5743 */
58- virtual bool motorReady ();
59-
44+ virtual bool startSlewRateCalibration () { return false ; };
6045 /* *
61- * @brief Gets the encoder managed by this driver.
62- * @return A pointer to the encoder instance.
46+ * Check if calibration is in process
47+ * @return the state of calibration process
6348 */
64- virtual Encoder* getEncoder ();
65-
66- /* *
67- * @brief Sets an external encoder for drivers that don't have an integrated one.
68- * @param encoder A shared pointer to the external encoder.
69- */
70- virtual void setEncoder (std::shared_ptr<Encoder>& encoder){drvEncoder = encoder;}
71-
72- /* *
73- * @brief Checks if the driver has an integrated encoder.
74- * @return true if integrated, false if external.
75- */
76- virtual bool hasIntegratedEncoder ();
77-
49+ virtual bool isSlewRateCalibrationInProgress () { return false ; };
7850 /* *
79- * @brief Gets the hardware measured maximum slew rate of the driver.
80- * @return The maximum slew rate in units/ms.
51+ * Get the value of the Slew Rate after a calibration
52+ * @return
8153 */
82- virtual uint32_t getDrvSlewRate () { return MAX_SLEW_RATE; }
54+ virtual uint16_t getDrvSlewRate () { return MAX_SLEW_RATE; };
55+
56+ virtual bool motorReady (); // Returns true if the driver is active and ready to receive commands
8357
84- /* *
85- * @brief Starts a calibration procedure to measure the driver's max slew rate.
86- * @return true if calibration started successfully.
87- */
88- virtual bool startSlewRateCalibration () { return false ; }
58+ virtual Encoder* getEncoder (); // Encoder is managed by the motor driver. Must always return an encoder
8959
9060 /* *
91- * @brief Performs initial setup and configuration of the driver.
61+ * Can pass an external encoder if driver has no integrated encoder
62+ * This allows a driver to get an external encoder assigned if it requires one and has the capability of using external encoders
9263 */
93- virtual void setupDriver () {}
94-
95- /* *
96- * @brief Sets the maximum power/current limit for the driver.
97- * @param power The power limit value.
98- */
99- virtual void setPowerLimit (uint16_t power) {}
64+ virtual void setEncoder (std::shared_ptr<Encoder>& encoder){drvEncoder = encoder;}
65+ virtual bool hasIntegratedEncoder (); // Returns true if the driver has an integrated encoder. If false the axis will pass one to the driver
10066
10167
10268protected:
103- std::shared_ptr<Encoder> drvEncoder = std::make_shared<Encoder>(); // !< Pointer to the encoder (integrated or external).
69+ std::shared_ptr<Encoder> drvEncoder = std::make_shared<Encoder>(); // Dummy encoder
10470};
10571
10672
0 commit comments