Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MotorDriver by
Diff: MotorDriver.h
- Revision:
- 4:9283a3f684af
- Parent:
- 3:7a6365365ee2
--- a/MotorDriver.h Thu Apr 28 02:38:16 2016 +0000
+++ b/MotorDriver.h Sat Apr 30 05:38:43 2016 +0000
@@ -5,9 +5,9 @@
General/Basic Motor Driver Class providing Motor Control using a COTS Motor Driver
Class based off of Christopher Hasler's Motordriver library found at
- https://developer.mbed.org/cookbook/Motor
-
-
+ https://developer.mbed.org/cookbook/Motor
+
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@@ -32,26 +32,19 @@
#include "mbed.h"
-/** Code_t enum
- * Provides motor states
- *
- * MOTOR_ERROR = 0
- * DRIVING_CW = 1
- * DRIVING_CCW = 2
- * BRAKING = 3
- * COASTING = 4
- */
-typedef enum {MOTOR_ERROR=0, DRIVING_CW=1, DRIVING_CCW=2, BRAKING=3, COASTING=4}Code_t;
-/** State_t struct
- * The code and value of the state of the motor.
- *
- * @note Code_t code
- * @note float value
- */
-typedef struct{
- Code_t code;
- float value;
-}State_t;
+/** The state of the motor */
+typedef enum {
+ MOTOR_ERROR=0, /**< Motor Error Mode */
+ DRIVING_CW=1, /**< Driving Clockwise (forward) */
+ DRIVING_CCW=2, /**< Driving Counter-Clockwise (reverse) */
+ BRAKING=3, /**< Braking Mode */
+ COASTING=4 /**< Coasting Mode */
+} Code_t;
+/** The code and value of the state of the motor. */
+typedef struct {
+ Code_t code; /**< The Code_t enum of the motor state */
+ float value; /**< The numerical value of the motor state */
+} State_t;
/** MotorDriver class.
* Used for DIY project "RC-AutoBot" by Clownface.space
*
@@ -61,7 +54,7 @@
* #include "MotorDriver.h"
*
* MotorDriver m1(in1, in2, pwm);
- *
+ *
* void dist(int distance)
* {
* //put code here to happen when the distance is changed
@@ -74,67 +67,62 @@
* }
* @endcode
*/
-class MotorDriver{
- public:
- /**
- Constructor of MotorDriver Objects
- @param in_1 Direction Input 1
- @param in_2 Direction Input 2
- @param pwm PWM speed control input
- @param pwmFreq PWM frequency, some motors may whine at lower freqs
- @param isBrakable Boolean value indicating whether or not the
- motor driver is brakeable(see your datasheet)
- */
- MotorDriver(DigitalOut in1, DigitalOut in2, PwmOut pwm, float pwmFreq, bool isBrakeable = false);
-
- /**
- Sets speed of motor normalized between -1.0 to 1.0
- @param speed Value -1.0 to 1.0 (>0 CW at speed as percentage)
- (<0 CCW at speed as percentage)
- (=0 speed is zero)
- @return state of the motor
- NOTE: This method will NOT allow user to instantaneously swithch
- from CW to CCW or vise versa. Doing so will cause the motor to
- be put in to a BRAKE condition, while the motor_state.code will
- be updated to MOTOR_ERROR. User should avoid trying to do this, call
- first setSpeed(0) or brake().
- */
- State_t setSpeed(float speed);
-
- /**
- Same as setSpeed(float speed), however does not impose the safety disallowing
- instantaneous reversal of motor direction. It is up to the user to ensure they
- do not blow up their motor.
-
- @param speed How fast to run the motor
- */
- State_t forceSetSpeed(float speed);
-
- /**
- Put motor into braked config
- @param intensity How hard to brake (0.0 to 1.0)
- @return state of the motors
- */
- State_t brake(float intensity);
-
- /**
- Put motor into stop/coast config
- */
- State_t coast();
-
- /**
- Get state of the motor
- @return state of the motor
- */
- State_t getState();
-
- protected: // Protected so objects that inherit can access
- State_t motor_state;
- DigitalOut _in1;
- DigitalOut _in2;
- PwmOut _pwm;
- bool isBrakeable;
- void determineState(); // Determine motor state based on in1, in2, and pwm
+class MotorDriver
+{
+public:
+ /** Constructor of MotorDriver Objects
+ @param in_1 Direction Input 1
+ @param in_2 Direction Input 2
+ @param pwm PWM speed control input
+ @param pwmFreq PWM frequency, some motors may whine at lower freqs
+ @param isBrakable Boolean value indicating whether or not the
+ motor driver is brakeable(see your datasheet)
+ */
+ MotorDriver(DigitalOut in1, DigitalOut in2, PwmOut pwm, float pwmFreq, bool isBrakeable = false);
+
+ /** Sets speed of motor normalized between -1.0 to 1.0
+ @param speed Value -1.0 to 1.0 (>0 CW at speed as percentage)
+ (<0 CCW at speed as percentage)
+ (=0 speed is zero)
+ @return state of the motor
+ NOTE: This method will NOT allow user to instantaneously swithch
+ from CW to CCW or vise versa. Doing so will cause the motor to
+ be put in to a BRAKE condition, while the motor_state.code will
+ be updated to MOTOR_ERROR. User should avoid trying to do this, call
+ first setSpeed(0) or brake().
+ */
+ State_t setSpeed(float speed);
+
+ /** Same as setSpeed(float speed), however does not impose the safety disallowing
+ instantaneous reversal of motor direction. It is up to the user to ensure they
+ do not blow up their motor.
+
+ @param speed How fast to run the motor
+ */
+ State_t forceSetSpeed(float speed);
+
+ /** Put motor into braked config
+ @param intensity How hard to brake (0.0 to 1.0)
+ @return state of the motors
+ */
+ State_t brake(float intensity);
+
+ /** Put motor into stop/coast config
+ */
+ State_t coast();
+
+ /** Get state of the motor
+ @return state of the motor
+ */
+ State_t getState();
+
+protected: // Protected so objects that inherit can access
+ State_t motor_state;
+ DigitalOut _in1;
+ DigitalOut _in2;
+ PwmOut _pwm;
+ bool isBrakeable;
+ void determineState(); // Determine motor state based on in1, in2, and pwm
};
#endif
\ No newline at end of file
