Telescope Control Library

Dependents:   PushToGo-F429

Committer:
caoyu@caoyuan9642-desktop.MIT.EDU
Date:
Mon Sep 24 19:36:48 2018 -0400
Revision:
19:fd854309cb4c
Parent:
0:6cb2eaf8b133
Fix bug in nudging with small speeds mentioned in the last commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
caoyuan9642 0:6cb2eaf8b133 1 /*
caoyuan9642 0:6cb2eaf8b133 2 * GenericStepperMotor.h
caoyuan9642 0:6cb2eaf8b133 3 *
caoyuan9642 0:6cb2eaf8b133 4 * Created on: 2018Äê2ÔÂ8ÈÕ
caoyuan9642 0:6cb2eaf8b133 5 * Author: caoyuan9642
caoyuan9642 0:6cb2eaf8b133 6 */
caoyuan9642 0:6cb2eaf8b133 7
caoyuan9642 0:6cb2eaf8b133 8 #ifndef TELESCOPE_STEPPERMOTOR_H_
caoyuan9642 0:6cb2eaf8b133 9 #define TELESCOPE_STEPPERMOTOR_H_
caoyuan9642 0:6cb2eaf8b133 10
caoyuan9642 0:6cb2eaf8b133 11 #include <stdint.h>
caoyuan9642 0:6cb2eaf8b133 12
caoyuan9642 0:6cb2eaf8b133 13 typedef enum
caoyuan9642 0:6cb2eaf8b133 14 {
caoyuan9642 0:6cb2eaf8b133 15 STEP_FORWARD = 0, STEP_BACKWARD = 1
caoyuan9642 0:6cb2eaf8b133 16 } stepdir_t;
caoyuan9642 0:6cb2eaf8b133 17
caoyuan9642 0:6cb2eaf8b133 18 /**
caoyuan9642 0:6cb2eaf8b133 19 * Interface of a generic stepper motor
caoyuan9642 0:6cb2eaf8b133 20 */
caoyuan9642 0:6cb2eaf8b133 21 class StepperMotor
caoyuan9642 0:6cb2eaf8b133 22 {
caoyuan9642 0:6cb2eaf8b133 23 protected:
caoyuan9642 0:6cb2eaf8b133 24 bool invert;
caoyuan9642 0:6cb2eaf8b133 25 public:
caoyuan9642 0:6cb2eaf8b133 26 StepperMotor(bool invert = false) :
caoyuan9642 0:6cb2eaf8b133 27 invert(invert)
caoyuan9642 0:6cb2eaf8b133 28 {
caoyuan9642 0:6cb2eaf8b133 29 }
caoyuan9642 0:6cb2eaf8b133 30 virtual ~StepperMotor()
caoyuan9642 0:6cb2eaf8b133 31 {
caoyuan9642 0:6cb2eaf8b133 32 }
caoyuan9642 0:6cb2eaf8b133 33
caoyuan9642 0:6cb2eaf8b133 34 /**
caoyuan9642 0:6cb2eaf8b133 35 * Start the stepper motor in the specified direction
caoyuan9642 0:6cb2eaf8b133 36 * @param dir direction to move
caoyuan9642 0:6cb2eaf8b133 37 * @note must be implemented
caoyuan9642 0:6cb2eaf8b133 38 */
caoyuan9642 0:6cb2eaf8b133 39 virtual void start(stepdir_t dir) = 0;
caoyuan9642 0:6cb2eaf8b133 40
caoyuan9642 0:6cb2eaf8b133 41 /**
caoyuan9642 0:6cb2eaf8b133 42 * Stop the stepper motor;
caoyuan9642 0:6cb2eaf8b133 43 */
caoyuan9642 0:6cb2eaf8b133 44 virtual void stop() = 0;
caoyuan9642 0:6cb2eaf8b133 45
caoyuan9642 0:6cb2eaf8b133 46 /**
caoyuan9642 0:6cb2eaf8b133 47 * Get the (fractional) step count. The unit is full steps, so half step will be 0.5 step and etc
caoyuan9642 0:6cb2eaf8b133 48 * @return step count
caoyuan9642 0:6cb2eaf8b133 49 */
caoyuan9642 0:6cb2eaf8b133 50 virtual double getStepCount() = 0;
caoyuan9642 0:6cb2eaf8b133 51
caoyuan9642 0:6cb2eaf8b133 52 /**
caoyuan9642 0:6cb2eaf8b133 53 * Set the current step count to specified value
caoyuan9642 0:6cb2eaf8b133 54 * @param count step count to be set to
caoyuan9642 0:6cb2eaf8b133 55 */
caoyuan9642 0:6cb2eaf8b133 56 virtual void setStepCount(double count) = 0;
caoyuan9642 0:6cb2eaf8b133 57
caoyuan9642 0:6cb2eaf8b133 58 /** Set frequency of the stepping. In unit of full steps per second
caoyuan9642 0:6cb2eaf8b133 59 * @param freq Target frequency in full steps per second
caoyuan9642 0:6cb2eaf8b133 60 * @return Actual frequency been set to. In full steps per second.
caoyuan9642 0:6cb2eaf8b133 61 * @note This value should be always SMALLER than the target frequency
caoyuan9642 0:6cb2eaf8b133 62 * when the accurate frequency cannot be achieved
caoyuan9642 0:6cb2eaf8b133 63 */
caoyuan9642 0:6cb2eaf8b133 64 virtual double setFrequency(double freq) = 0;
caoyuan9642 0:6cb2eaf8b133 65
caoyuan9642 0:6cb2eaf8b133 66 /**
caoyuan9642 0:6cb2eaf8b133 67 * Turn off the motor power
caoyuan9642 0:6cb2eaf8b133 68 */
caoyuan9642 0:6cb2eaf8b133 69 virtual void poweroff(){
caoyuan9642 0:6cb2eaf8b133 70 }
caoyuan9642 0:6cb2eaf8b133 71
caoyuan9642 0:6cb2eaf8b133 72 /**
caoyuan9642 0:6cb2eaf8b133 73 * Turn on the motor power
caoyuan9642 0:6cb2eaf8b133 74 */
caoyuan9642 0:6cb2eaf8b133 75 virtual void poweron(){
caoyuan9642 0:6cb2eaf8b133 76 }
caoyuan9642 0:6cb2eaf8b133 77
caoyuan9642 0:6cb2eaf8b133 78 /**
caoyuan9642 0:6cb2eaf8b133 79 * Set microsteps
caoyuan9642 0:6cb2eaf8b133 80 * @param microstep Microstep setting to use
caoyuan9642 0:6cb2eaf8b133 81 * @note to be overriden by application if available
caoyuan9642 0:6cb2eaf8b133 82 */
caoyuan9642 0:6cb2eaf8b133 83 virtual void setMicroStep(int microstep)
caoyuan9642 0:6cb2eaf8b133 84 {
caoyuan9642 0:6cb2eaf8b133 85 }
caoyuan9642 0:6cb2eaf8b133 86
caoyuan9642 0:6cb2eaf8b133 87 /**
caoyuan9642 0:6cb2eaf8b133 88 * Set drive current
caoyuan9642 0:6cb2eaf8b133 89 * @param current new current to use
caoyuan9642 0:6cb2eaf8b133 90 * @note to be overriden by application if available
caoyuan9642 0:6cb2eaf8b133 91 */
caoyuan9642 0:6cb2eaf8b133 92 virtual void setCurrent(double current)
caoyuan9642 0:6cb2eaf8b133 93 {
caoyuan9642 0:6cb2eaf8b133 94 }
caoyuan9642 0:6cb2eaf8b133 95
caoyuan9642 0:6cb2eaf8b133 96 };
caoyuan9642 0:6cb2eaf8b133 97
caoyuan9642 0:6cb2eaf8b133 98 /**
caoyuan9642 0:6cb2eaf8b133 99 * Take inverse of the stepping direction
caoyuan9642 0:6cb2eaf8b133 100 */
caoyuan9642 0:6cb2eaf8b133 101 inline stepdir_t operator!(const stepdir_t dir)
caoyuan9642 0:6cb2eaf8b133 102 {
caoyuan9642 0:6cb2eaf8b133 103 if (dir == STEP_FORWARD)
caoyuan9642 0:6cb2eaf8b133 104 return STEP_BACKWARD;
caoyuan9642 0:6cb2eaf8b133 105 else
caoyuan9642 0:6cb2eaf8b133 106 return STEP_FORWARD;
caoyuan9642 0:6cb2eaf8b133 107 }
caoyuan9642 0:6cb2eaf8b133 108
caoyuan9642 0:6cb2eaf8b133 109 #endif /* TELESCOPE_STEPPERMOTOR_H_ */
caoyuan9642 0:6cb2eaf8b133 110
caoyuan9642 0:6cb2eaf8b133 111