motor control
Fork of X_NUCLEO_IHM01A1 by
Components/Interfaces/StepperMotor_class.h@26:7ac4b4c49276, 2016-04-02 (annotated)
- Committer:
- julientiron
- Date:
- Sat Apr 02 10:06:38 2016 +0000
- Revision:
- 26:7ac4b4c49276
- Parent:
- 20:a8e81b65f0af
l; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Davidroid | 4:83a1eb397a65 | 1 | /** |
Davidroid | 4:83a1eb397a65 | 2 | ****************************************************************************** |
Davidroid | 4:83a1eb397a65 | 3 | * @file StepperMotor_class.h |
Davidroid | 20:a8e81b65f0af | 4 | * @author Davide Aliprandi, STMicroelectronics |
Davidroid | 4:83a1eb397a65 | 5 | * @version V1.0.0 |
Davidroid | 4:83a1eb397a65 | 6 | * @date November 12th, 2015 |
Davidroid | 4:83a1eb397a65 | 7 | * @brief This file contains the abstract class describing the interface of a |
Davidroid | 8:42e0b00b1e4d | 8 | * stepper-motor component. |
Davidroid | 4:83a1eb397a65 | 9 | ****************************************************************************** |
Davidroid | 4:83a1eb397a65 | 10 | * @attention |
Davidroid | 4:83a1eb397a65 | 11 | * |
Davidroid | 4:83a1eb397a65 | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
Davidroid | 4:83a1eb397a65 | 13 | * |
Davidroid | 4:83a1eb397a65 | 14 | * Redistribution and use in source and binary forms, with or without modification, |
Davidroid | 4:83a1eb397a65 | 15 | * are permitted provided that the following conditions are met: |
Davidroid | 4:83a1eb397a65 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
Davidroid | 4:83a1eb397a65 | 17 | * this list of conditions and the following disclaimer. |
Davidroid | 4:83a1eb397a65 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Davidroid | 4:83a1eb397a65 | 19 | * this list of conditions and the following disclaimer in the documentation |
Davidroid | 4:83a1eb397a65 | 20 | * and/or other materials provided with the distribution. |
Davidroid | 4:83a1eb397a65 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Davidroid | 4:83a1eb397a65 | 22 | * may be used to endorse or promote products derived from this software |
Davidroid | 4:83a1eb397a65 | 23 | * without specific prior written permission. |
Davidroid | 4:83a1eb397a65 | 24 | * |
Davidroid | 4:83a1eb397a65 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Davidroid | 4:83a1eb397a65 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Davidroid | 4:83a1eb397a65 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Davidroid | 4:83a1eb397a65 | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Davidroid | 4:83a1eb397a65 | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Davidroid | 4:83a1eb397a65 | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Davidroid | 4:83a1eb397a65 | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Davidroid | 4:83a1eb397a65 | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Davidroid | 4:83a1eb397a65 | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Davidroid | 4:83a1eb397a65 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Davidroid | 4:83a1eb397a65 | 35 | * |
Davidroid | 4:83a1eb397a65 | 36 | ****************************************************************************** |
Davidroid | 4:83a1eb397a65 | 37 | */ |
Davidroid | 4:83a1eb397a65 | 38 | |
Davidroid | 4:83a1eb397a65 | 39 | |
Davidroid | 4:83a1eb397a65 | 40 | /* Define to prevent from recursive inclusion --------------------------------*/ |
Davidroid | 4:83a1eb397a65 | 41 | |
Davidroid | 4:83a1eb397a65 | 42 | #ifndef __STEPPERMOTOR_CLASS_H |
Davidroid | 4:83a1eb397a65 | 43 | #define __STEPPERMOTOR_CLASS_H |
Davidroid | 4:83a1eb397a65 | 44 | |
Davidroid | 4:83a1eb397a65 | 45 | |
Davidroid | 4:83a1eb397a65 | 46 | /* Includes ------------------------------------------------------------------*/ |
Davidroid | 4:83a1eb397a65 | 47 | |
Davidroid | 4:83a1eb397a65 | 48 | #include <Component_class.h> |
Davidroid | 4:83a1eb397a65 | 49 | |
Davidroid | 4:83a1eb397a65 | 50 | |
Davidroid | 4:83a1eb397a65 | 51 | /* Classes ------------------------------------------------------------------*/ |
Davidroid | 4:83a1eb397a65 | 52 | |
Davidroid | 4:83a1eb397a65 | 53 | /** An abstract class for StepperMotor components. |
Davidroid | 4:83a1eb397a65 | 54 | */ |
Davidroid | 4:83a1eb397a65 | 55 | class StepperMotor : public Component |
Davidroid | 4:83a1eb397a65 | 56 | { |
Davidroid | 4:83a1eb397a65 | 57 | public: |
Davidroid | 10:c3824af0caf4 | 58 | /** |
Davidroid | 10:c3824af0caf4 | 59 | * @brief Rotation modes. |
Davidroid | 10:c3824af0caf4 | 60 | */ |
Davidroid | 4:83a1eb397a65 | 61 | typedef enum |
Davidroid | 4:83a1eb397a65 | 62 | { |
Davidroid | 5:d3c78f12a78d | 63 | BWD = 0, /* Backward. */ |
Davidroid | 5:d3c78f12a78d | 64 | FWD = 1 /* Forward. */ |
Davidroid | 4:83a1eb397a65 | 65 | } direction_t; |
Davidroid | 4:83a1eb397a65 | 66 | |
Davidroid | 7:f7e0c3621f77 | 67 | /** |
Davidroid | 8:42e0b00b1e4d | 68 | * @brief Getting the status. |
Davidroid | 7:f7e0c3621f77 | 69 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 70 | * @retval The status. |
Davidroid | 7:f7e0c3621f77 | 71 | */ |
Davidroid | 4:83a1eb397a65 | 72 | virtual unsigned int GetStatus(void) = 0; |
Davidroid | 4:83a1eb397a65 | 73 | |
Davidroid | 8:42e0b00b1e4d | 74 | /** |
Davidroid | 7:f7e0c3621f77 | 75 | * @brief Getting a parameter. |
Davidroid | 8:42e0b00b1e4d | 76 | * @param parameter The parameter's identifier (or its register address). |
Davidroid | 8:42e0b00b1e4d | 77 | * @retval The parameter's value. |
Davidroid | 7:f7e0c3621f77 | 78 | */ |
Davidroid | 19:5f0b00a1e38d | 79 | virtual float GetParameter(unsigned int parameter) = 0; |
Davidroid | 4:83a1eb397a65 | 80 | |
Davidroid | 8:42e0b00b1e4d | 81 | /** |
Davidroid | 8:42e0b00b1e4d | 82 | * @brief Getting the position. |
Davidroid | 8:42e0b00b1e4d | 83 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 84 | * @retval The position. |
Davidroid | 8:42e0b00b1e4d | 85 | */ |
Davidroid | 4:83a1eb397a65 | 86 | virtual signed int GetPosition(void) = 0; |
Davidroid | 4:83a1eb397a65 | 87 | |
Davidroid | 8:42e0b00b1e4d | 88 | /** |
Davidroid | 8:42e0b00b1e4d | 89 | * @brief Getting the marked position. |
Davidroid | 8:42e0b00b1e4d | 90 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 91 | * @retval The marked position. |
Davidroid | 8:42e0b00b1e4d | 92 | */ |
Davidroid | 4:83a1eb397a65 | 93 | virtual signed int GetMark(void) = 0; |
Davidroid | 4:83a1eb397a65 | 94 | |
Davidroid | 8:42e0b00b1e4d | 95 | /** |
Davidroid | 8:42e0b00b1e4d | 96 | * @brief Getting the current speed in pps. |
Davidroid | 8:42e0b00b1e4d | 97 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 98 | * @retval The current speed in pps. |
Davidroid | 8:42e0b00b1e4d | 99 | */ |
Davidroid | 4:83a1eb397a65 | 100 | virtual unsigned int GetSpeed(void) = 0; |
Davidroid | 4:83a1eb397a65 | 101 | |
Davidroid | 8:42e0b00b1e4d | 102 | /** |
Davidroid | 8:42e0b00b1e4d | 103 | * @brief Getting the maximum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 104 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 105 | * @retval The maximum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 106 | */ |
Davidroid | 4:83a1eb397a65 | 107 | virtual unsigned int GetMaxSpeed(void) = 0; |
Davidroid | 4:83a1eb397a65 | 108 | |
Davidroid | 8:42e0b00b1e4d | 109 | /** |
Davidroid | 8:42e0b00b1e4d | 110 | * @brief Getting the minimum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 111 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 112 | * @retval The minimum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 113 | */ |
Davidroid | 4:83a1eb397a65 | 114 | virtual unsigned int GetMinSpeed(void) = 0; |
Davidroid | 4:83a1eb397a65 | 115 | |
Davidroid | 8:42e0b00b1e4d | 116 | /** |
Davidroid | 8:42e0b00b1e4d | 117 | * @brief Getting the acceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 118 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 119 | * @retval The acceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 120 | */ |
Davidroid | 4:83a1eb397a65 | 121 | virtual unsigned int GetAcceleration(void) = 0; |
Davidroid | 4:83a1eb397a65 | 122 | |
Davidroid | 8:42e0b00b1e4d | 123 | /** |
Davidroid | 8:42e0b00b1e4d | 124 | * @brief Getting the deceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 125 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 126 | * @retval The deceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 127 | */ |
Davidroid | 4:83a1eb397a65 | 128 | virtual unsigned int GetDeceleration(void) = 0; |
Davidroid | 4:83a1eb397a65 | 129 | |
Davidroid | 8:42e0b00b1e4d | 130 | /** |
Davidroid | 8:42e0b00b1e4d | 131 | * @brief Getting the direction of rotation. |
Davidroid | 8:42e0b00b1e4d | 132 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 133 | * @retval The direction of rotation. |
Davidroid | 8:42e0b00b1e4d | 134 | */ |
Davidroid | 5:d3c78f12a78d | 135 | virtual direction_t GetDirection(void) = 0; |
Davidroid | 5:d3c78f12a78d | 136 | |
Davidroid | 7:f7e0c3621f77 | 137 | /** |
Davidroid | 7:f7e0c3621f77 | 138 | * @brief Setting a parameter. |
Davidroid | 8:42e0b00b1e4d | 139 | * @param parameter The parameter's identifier (or its register address). |
Davidroid | 8:42e0b00b1e4d | 140 | * @param value The parameter's value. |
Davidroid | 7:f7e0c3621f77 | 141 | * @retval None. |
Davidroid | 7:f7e0c3621f77 | 142 | */ |
Davidroid | 19:5f0b00a1e38d | 143 | virtual void SetParameter(unsigned int parameter, float value) = 0; |
Davidroid | 4:83a1eb397a65 | 144 | |
Davidroid | 8:42e0b00b1e4d | 145 | /** |
Davidroid | 8:42e0b00b1e4d | 146 | * @brief Setting the current position to be the home position. |
Davidroid | 8:42e0b00b1e4d | 147 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 148 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 149 | */ |
Davidroid | 4:83a1eb397a65 | 150 | virtual void SetHome(void) = 0; |
Davidroid | 4:83a1eb397a65 | 151 | |
Davidroid | 8:42e0b00b1e4d | 152 | /** |
Davidroid | 8:42e0b00b1e4d | 153 | * @brief Setting the current position to be the marked position. |
Davidroid | 8:42e0b00b1e4d | 154 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 155 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 156 | */ |
Davidroid | 4:83a1eb397a65 | 157 | virtual void SetMark(void) = 0; |
Davidroid | 4:83a1eb397a65 | 158 | |
Davidroid | 8:42e0b00b1e4d | 159 | /** |
Davidroid | 8:42e0b00b1e4d | 160 | * @brief Setting the maximum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 161 | * @param speed The maximum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 162 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 163 | */ |
Davidroid | 4:83a1eb397a65 | 164 | virtual void SetMaxSpeed(unsigned int speed) = 0; |
Davidroid | 4:83a1eb397a65 | 165 | |
Davidroid | 8:42e0b00b1e4d | 166 | /** |
Davidroid | 8:42e0b00b1e4d | 167 | * @brief Setting the minimum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 168 | * @param speed The minimum speed in pps. |
Davidroid | 8:42e0b00b1e4d | 169 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 170 | */ |
Davidroid | 4:83a1eb397a65 | 171 | virtual void SetMinSpeed(unsigned int speed) = 0; |
Davidroid | 4:83a1eb397a65 | 172 | |
Davidroid | 8:42e0b00b1e4d | 173 | /** |
Davidroid | 8:42e0b00b1e4d | 174 | * @brief Setting the acceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 175 | * @param acceleration The acceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 176 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 177 | */ |
Davidroid | 4:83a1eb397a65 | 178 | virtual void SetAcceleration(unsigned int acceleration) = 0; |
Davidroid | 4:83a1eb397a65 | 179 | |
Davidroid | 8:42e0b00b1e4d | 180 | /** |
Davidroid | 8:42e0b00b1e4d | 181 | * @brief Setting the deceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 182 | * @param deceleration The deceleration in pps^2. |
Davidroid | 8:42e0b00b1e4d | 183 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 184 | */ |
Davidroid | 4:83a1eb397a65 | 185 | virtual void SetDeceleration(unsigned int deceleration) = 0; |
Davidroid | 4:83a1eb397a65 | 186 | |
Davidroid | 8:42e0b00b1e4d | 187 | /** |
Davidroid | 8:42e0b00b1e4d | 188 | * @brief Going to a specified position. |
Davidroid | 8:42e0b00b1e4d | 189 | * @param position The desired position. |
Davidroid | 8:42e0b00b1e4d | 190 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 191 | */ |
Davidroid | 4:83a1eb397a65 | 192 | virtual void GoTo(signed int position) = 0; |
Davidroid | 4:83a1eb397a65 | 193 | |
Davidroid | 8:42e0b00b1e4d | 194 | /** |
Davidroid | 8:42e0b00b1e4d | 195 | * @brief Going to the home position. |
Davidroid | 8:42e0b00b1e4d | 196 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 197 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 198 | */ |
Davidroid | 4:83a1eb397a65 | 199 | virtual void GoHome(void) = 0; |
Davidroid | 4:83a1eb397a65 | 200 | |
Davidroid | 8:42e0b00b1e4d | 201 | /** |
Davidroid | 8:42e0b00b1e4d | 202 | * @brief Going to the marked position. |
Davidroid | 8:42e0b00b1e4d | 203 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 204 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 205 | */ |
Davidroid | 4:83a1eb397a65 | 206 | virtual void GoMark(void) = 0; |
Davidroid | 4:83a1eb397a65 | 207 | |
Davidroid | 8:42e0b00b1e4d | 208 | /** |
Davidroid | 8:42e0b00b1e4d | 209 | * @brief Running the motor towards a specified direction. |
Davidroid | 8:42e0b00b1e4d | 210 | * @param direction The direction of rotation. |
Davidroid | 8:42e0b00b1e4d | 211 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 212 | */ |
Davidroid | 4:83a1eb397a65 | 213 | virtual void Run(direction_t direction) = 0; |
Davidroid | 4:83a1eb397a65 | 214 | |
Davidroid | 8:42e0b00b1e4d | 215 | /** |
Davidroid | 8:42e0b00b1e4d | 216 | * @brief Moving the motor towards a specified direction for a certain number of steps. |
Davidroid | 8:42e0b00b1e4d | 217 | * @param direction The direction of rotation. |
Davidroid | 8:42e0b00b1e4d | 218 | * @param steps The desired number of steps. |
Davidroid | 8:42e0b00b1e4d | 219 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 220 | */ |
Davidroid | 4:83a1eb397a65 | 221 | virtual void Move(direction_t direction, unsigned int steps) = 0; |
Davidroid | 4:83a1eb397a65 | 222 | |
Davidroid | 8:42e0b00b1e4d | 223 | /** |
Davidroid | 13:ba2728afe4c2 | 224 | * @brief Stopping the motor through an immediate deceleration up to zero speed. |
Davidroid | 8:42e0b00b1e4d | 225 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 226 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 227 | */ |
Davidroid | 4:83a1eb397a65 | 228 | virtual void SoftStop(void) = 0; |
Davidroid | 4:83a1eb397a65 | 229 | |
Davidroid | 8:42e0b00b1e4d | 230 | /** |
Davidroid | 13:ba2728afe4c2 | 231 | * @brief Stopping the motor through an immediate infinite deceleration. |
Davidroid | 8:42e0b00b1e4d | 232 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 233 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 234 | */ |
Davidroid | 4:83a1eb397a65 | 235 | virtual void HardStop(void) = 0; |
Davidroid | 7:f7e0c3621f77 | 236 | |
Davidroid | 8:42e0b00b1e4d | 237 | /** |
Davidroid | 13:ba2728afe4c2 | 238 | * @brief Disabling the power bridge after performing a deceleration to zero. |
Davidroid | 13:ba2728afe4c2 | 239 | * @param None. |
Davidroid | 13:ba2728afe4c2 | 240 | * @retval None. |
Davidroid | 13:ba2728afe4c2 | 241 | */ |
Davidroid | 13:ba2728afe4c2 | 242 | virtual void SoftHiZ(void) = 0; |
Davidroid | 13:ba2728afe4c2 | 243 | |
Davidroid | 13:ba2728afe4c2 | 244 | /** |
Davidroid | 13:ba2728afe4c2 | 245 | * @brief Disabling the power bridge immediately. |
Davidroid | 13:ba2728afe4c2 | 246 | * @param None. |
Davidroid | 13:ba2728afe4c2 | 247 | * @retval None. |
Davidroid | 13:ba2728afe4c2 | 248 | */ |
Davidroid | 13:ba2728afe4c2 | 249 | virtual void HardHiZ(void) = 0; |
Davidroid | 13:ba2728afe4c2 | 250 | |
Davidroid | 13:ba2728afe4c2 | 251 | /** |
Davidroid | 8:42e0b00b1e4d | 252 | * @brief Waiting while the motor is active. |
Davidroid | 8:42e0b00b1e4d | 253 | * @param None. |
Davidroid | 8:42e0b00b1e4d | 254 | * @retval None. |
Davidroid | 8:42e0b00b1e4d | 255 | */ |
Davidroid | 7:f7e0c3621f77 | 256 | virtual void WaitWhileActive(void) = 0; |
Davidroid | 4:83a1eb397a65 | 257 | }; |
Davidroid | 4:83a1eb397a65 | 258 | |
Davidroid | 4:83a1eb397a65 | 259 | #endif /* __STEPPERMOTOR_CLASS_H */ |
Davidroid | 4:83a1eb397a65 | 260 | |
Davidroid | 4:83a1eb397a65 | 261 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |