MotorWare f2806x Module API Documentation
spintac_vel_ctl.h
Go to the documentation of this file.
1 #ifndef __SPINTAC_VEL_CTL_H__
2 #define __SPINTAC_VEL_CTL_H__
3 /* --COPYRIGHT--,BSD
4  * Copyright (c) 2012, LineStream Technologies Incorporated
5  * Copyright (c) 2012, Texas Instruments Incorporated
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * * Neither the names of Texas Instruments Incorporated, LineStream
20  * Technologies Incorporated, nor the names of its contributors may be
21  * used to endorse or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
34  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  * --/COPYRIGHT--*/
36 
43 
45 
46 
47 #include "spintac_version.h"
48 
49 #ifndef __ST_AXIS_ENUM__
50 #define __ST_AXIS_ENUM__
51 typedef enum
54 {
57 } ST_Axis_e;
58 #endif //__ST_AXIS_ENUM__
59 
60 #ifndef __ST_CTL_STATUS_ENUM__
61 #define __ST_CTL_STATUS_ENUM__
62 typedef enum
65 {
71 #endif //__ST_CTL_STATUS_ENUM__
72 
76 typedef struct {
77  //System config parameters: Can be set only once at system startup
80  bool FiltEN;
81  // Config parameters that may be modified
84 } ST_VelCtlCfg_t; // Structure for SpinTAC Control-Velocity configuration
85 
89 typedef struct {
90  /* Configuration variables */
92  /* Input variables */
99  // Control bits
100  bool ENB;
101  /* Output variables */
103  // Information variables
105  uint16_t ERR_ID;
106  /* Internal variables */
107  uint32_t s1[10];
108 } ST_VelCtl_t; // Structure for SpinTAC Velocity Control
109 
110 typedef struct _ST_VELCTL_Handle_ *ST_VELCTL_Handle; // SpinTAC Velocity Controller Handle
111 
115 static inline void STVELCTL_setAxis(ST_VELCTL_Handle handle, ST_Axis_e axis) {
116  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
117 
118  if(obj->STATUS == ST_CTL_IDLE) {
119  obj->cfg.Axis = axis;
120  }
121 
122  return;
123 } // end of STVELCTL_setAxis function
124 
128 static inline void STVELCTL_setSampleTime_sec(ST_VELCTL_Handle handle, _iq24 sampleTime) {
129  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
130 
131  if(obj->STATUS == ST_CTL_IDLE) {
132  obj->cfg.T_sec = sampleTime;
133  }
134 
135  return;
136 } // end of STVELCTL_setSampleTime_sec function
137 
142  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
143 
144  return obj->cfg.OutMax;
145 } // end of STVELCTL_getOutputMaximum function
146 
151  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
152 
153  return obj->cfg.OutMin;
154 } // end of STVELCTL_getOutputMinimum function
155 
160 static inline void STVELCTL_setOutputMaximums(ST_VELCTL_Handle handle, _iq24 outMax, _iq24 outMin) {
161  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
162 
163  obj->cfg.OutMax = outMax;
164  obj->cfg.OutMin = outMin;
165 
166  return;
167 } // end of STVELCTL_setOutputMaximums function
168 
172 static inline void STVELCTL_setFilterEnableFlag(ST_VELCTL_Handle handle, bool filterEnable) {
173  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
174 
175  if(obj->STATUS == ST_CTL_IDLE) {
176  obj->cfg.FiltEN = filterEnable;
177  }
178 
179  return;
180 } // end of STVELCTL_setFilterEnableFlag function
181 
185 static inline void STVELCTL_setVelocityReference(ST_VELCTL_Handle handle, _iq24 velRef) {
186  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
187 
188  obj->VelRef = velRef;
189 
190  return;
191 } // end of STVELCTL_setVelocityReference function
192 
197  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
198 
199  return(obj->VelRef);
200 } // end of STVELCTL_getVelocityReference function
201 
205 static inline void STVELCTL_setAccelerationReference(ST_VELCTL_Handle handle, _iq24 accRef) {
206  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
207 
208  obj->AccRef = accRef;
209 
210  return;
211 } // end of STVELCTL_setAccelerationReference function
212 
216 static inline void STVELCTL_setVelocityFeedback(ST_VELCTL_Handle handle, _iq24 velFdb) {
217  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
218 
219  obj->VelFdb = velFdb;
220 
221  return;
222 } // end of STVELCTL_setVelocityFeedback function
223 
228  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
229 
230  return(obj->VelFdb);
231 } // end of STVELCTL_getVelocityFeedback function
232 
236 static inline void STVELCTL_setInertia(ST_VELCTL_Handle handle, _iq24 inertia) {
237  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
238 
239  obj->Inertia = inertia;
240 
241  return;
242 } // end of STVELCTL_setInertia function
243 
248  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
249 
250  return(obj->Inertia);
251 } // end of STVELCTL_getInertia function
252 
256 static inline void STVELCTL_setFriction(ST_VELCTL_Handle handle, _iq24 friction) {
257  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
258 
259  obj->Friction = friction;
260 
261  return;
262 } // end of STVELCTL_setFriction function
263 
268  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
269 
270  return(obj->Friction);
271 } // end of STVELCTL_getFriction function
272 
276 static inline void STVELCTL_setBandwidth_radps(ST_VELCTL_Handle handle, _iq20 bw) {
277  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
278 
279  obj->Bw_radps = bw;
280 
281  return;
282 } // end of STVELCTL_setBandwidth_radps function
283 
288  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
289 
290  return(obj->Bw_radps);
291 } // end of STVELCTL_getBandwidth_radps function
292 
296 static inline void STVELCTL_setEnable(ST_VELCTL_Handle handle, bool enb) {
297  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
298 
299  obj->ENB = enb;
300 
301  return;
302 } // end of STVELCTL_setEnable function
303 
307 static inline bool STVELCTL_getEnable(ST_VELCTL_Handle handle) {
308  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
309 
310  return (obj->ENB);
311 
312 } // end of STVELCTL_getEnable function
313 
317 static inline void STVELCTL_setTorqueReference(ST_VELCTL_Handle handle, _iq24 out) {
318  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
319 
320  obj->Out = out;
321 
322  return;
323 } // end of STVELCTL_setTorqueReference function
324 
329  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
330 
331  return (obj->Out);
332 } // end of STVELCTL_getTorqueReference function
333 
338  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
339 
340  return (obj->STATUS);
341 
342 } // end of STVELCTL_getStatus function
343 
347 static inline uint16_t STVELCTL_getErrorID(ST_VELCTL_Handle handle) {
348  ST_VelCtl_t *obj = (ST_VelCtl_t *)handle;
349 
350  return (obj->ERR_ID);
351 
352 } // end of STVELCTL_getErrorID function
353 
358 ST_VELCTL_Handle STVELCTL_init(void *pMemory, const size_t numBytes);
359 
362 void STVELCTL_run(ST_VELCTL_Handle handle); // SpinTAC Velocity Controller function
363 
365 #endif //__SPINTAC_VEL_CTL_H__
static void STVELCTL_setOutputMaximums(ST_VELCTL_Handle handle, _iq24 outMax, _iq24 outMin)
Sets the Maximum Output (cfg.OutMax) and Minimum Output (cfg.OutMin) for SpinTAC Velocity Controller...
bool ENB
Enable bit { false: disable; true: enable }.
ST_CTL in busy state.
static ST_CtlStatus_e STVELCTL_getStatus(ST_VELCTL_Handle handle)
Gets the Status value (STATUS) for SpinTAC Velocity Controller.
static _iq20 STVELCTL_getBandwidth_radps(ST_VELCTL_Handle handle)
Gets the Bandwidth (Bw_radps) for SpinTAC Velocity Controller.
ST_CtlStatus_e
Enumeration for the Control Status states.
_iq24 OutMax
Control signal upper limit { unit: [PU], value range: (-1.0, 1.0] }.
ST_VELCTL_Handle STVELCTL_init(void *pMemory, const size_t numBytes)
Initializes the SpinTAC Velocity Controller object.
static _iq24 STVELCTL_getOutputMinimum(ST_VELCTL_Handle handle)
Gets the Minimum Output (cfg.OutMin) for SpinTAC Velocity Controller.
static void STVELCTL_setVelocityReference(ST_VELCTL_Handle handle, _iq24 velRef)
Sets the Velocity Reference (VelRef) for SpinTAC Velocity Controller.
ST_Axis_e Axis
Axis ID { ST_AXIS0: axis 0, ST_AXIS1: axis 1}.
ST_CTL in conf state.
static _iq24 STVELCTL_getVelocityFeedback(ST_VELCTL_Handle handle)
Gets the Velocity Feedback (VelFdb) for SpinTAC Velocity Controller.
_iq24 T_sec
Sample time { unit: [s], value range: (0.0, 0.01] }.
bool FiltEN
Enable low-pass Filter { false: Filter Disabled; true: Filter Enabled }.
Defines the ST_VelCtl_t data.
static void STVELCTL_setVelocityFeedback(ST_VELCTL_Handle handle, _iq24 velFdb)
Sets the Velocity Feedback (VelFdb) for SpinTAC Velocity Controller.
static _iq24 STVELCTL_getTorqueReference(ST_VELCTL_Handle handle)
Gets the Torque (Iq) Reference (Out) for SpinTAC Velocity Controller.
static void STVELCTL_setSampleTime_sec(ST_VELCTL_Handle handle, _iq24 sampleTime)
Sets the Sample Time (cfg.T_sec) for SpinTAC Velocity Controller.
_iq24 Out
Control output { unit: [PU], value range: [cfg.OutMin, cfg.OutMax] }.
_iq24 Inertia
System inertia { unit: [PU/(pu/s^2)], value range: positive _IQ24 value }.
ST_CTL in idle state.
ST_CtlStatus_e
Enumeration for the Control Status states.
static void STVELCTL_setFilterEnableFlag(ST_VELCTL_Handle handle, bool filterEnable)
Sets the Feedback Filter Enable Flag (cfg.FiltEN) for SpinTAC Velocity Controller.
static _iq24 STVELCTL_getInertia(ST_VELCTL_Handle handle)
Gets the Inertia (Inertia) for SpinTAC Velocity Controller.
void STVELCTL_run(ST_VELCTL_Handle handle)
Runs the SpinTAC Velocity Control Function.
static _iq24 STVELCTL_getFriction(ST_VELCTL_Handle handle)
Gets the Friction (Friction) from SpinTAC Velocity Controller.
static void STVELCTL_setTorqueReference(ST_VELCTL_Handle handle, _iq24 out)
Sets the Torque (Iq) Reference (Out) for SpinTAC Velocity Controller.
static _iq24 STVELCTL_getVelocityReference(ST_VELCTL_Handle handle)
Gets the Velocity Reference (VelRef) for SpinTAC Velocity Controller.
Second Axis.
static _iq24 STVELCTL_getOutputMaximum(ST_VELCTL_Handle handle)
Gets the Maximum Output (cfg.OutMax) for SpinTAC Velocity Controller.
static bool STVELCTL_getEnable(ST_VELCTL_Handle handle)
Gets the Enable signal (ENB) for SpinTAC Velocity Controller.
long _iq24
static void STVELCTL_setAccelerationReference(ST_VELCTL_Handle handle, _iq24 accRef)
Sets the Acceleration Reference (AccRef) for SpinTAC Velocity Controller.
_iq24 VelRef
Reference input { unit: [pu/s], value range: [-1.0, 1.0] }.
Defines the ST_VelCtlCfg_t data.
ST_Axis_e
Enumeration for the Axis Status states.
ST_Axis_e
Enumeration for the Axis Status states.
ST_CTL in init state.
Public interface, object, and function definitions related to the SpinTAC Version object...
uint16_t ERR_ID
Error ID { 0: no error; others: see error code }.
ST_VelCtlCfg_t cfg
static uint16_t STVELCTL_getErrorID(ST_VELCTL_Handle handle)
Gets the Error value (ERR_ID) for SpinTAC Velocity Controller.
_iq24 AccRef
Feedforward input { unit: [pu/s^2] }.
First Axis.
_iq20 Bw_radps
Controller Bandwidth {unit: [rad/s], value range: [0.01, min(2000.0, 0.1/T_sec)] }.
static void STVELCTL_setInertia(ST_VELCTL_Handle handle, _iq24 inertia)
Sets the Inertia (Inertia) for SpinTAC Velocity Controller.
long _iq20
struct _ST_VELCTL_Handle_ * ST_VELCTL_Handle
static void STVELCTL_setFriction(ST_VELCTL_Handle handle, _iq24 friction)
Sets the Friction (Friction) for SpinTAC Velocity Controller.
static void STVELCTL_setEnable(ST_VELCTL_Handle handle, bool enb)
Sets the Enable signal (ENB) for SpinTAC Velocity Controller.
_iq24 OutMin
Control signal lower limit { unit: [PU], value range: [-1.0, OutMax) }.
static void STVELCTL_setAxis(ST_VELCTL_Handle handle, ST_Axis_e axis)
Sets the Axis (cfg.Axis) for SpinTAC Velocity Controller.
_iq24 VelFdb
Feedback input { unit: [pu/s], value range: [-1.0, 1.0] }.
ST_CtlStatus_e STATUS
Status { ST_CTL_IDLE, ST_CTL_INIT, ST_CTL_CONF, ST_CTL_BUSY }.
_iq24 Friction
Friction Coefficient { unit: [PU/(pu/s)], value range: positive _IQ24 value }.
static void STVELCTL_setBandwidth_radps(ST_VELCTL_Handle handle, _iq20 bw)
Sets the Bandwidth (Bw_radps) for SpinTAC Velocity Controller.