MotorWare f2806x Module API Documentation
spintac_pos_ctl.h
Go to the documentation of this file.
1 #ifndef __SPINTAC_POS_CTL_H__
2 #define __SPINTAC_POS_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
83  bool RampDist;
84  bool FiltEN;
85 
86  //Config parameters that may be modified
91 
95 typedef struct {
96  /* Configuration variables */
98  /* Input variables */
106  // Control bits
107  bool ENB;
108  /* Output variables */
110  // Information variables
112  uint16_t ERR_ID;
114  /* Internal variables */
115  uint32_t s1[18];
116 } ST_PosCtl_t; // Structure for SpinTAC Position Control
117 
118 typedef struct _ST_POSCTL_Handle_ *ST_POSCTL_Handle; // SpinTAC Position Controller Handle
119 
123 static inline void STPOSCTL_setAxis(ST_POSCTL_Handle handle, ST_Axis_e axis) {
124  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
125 
126  if(obj->STATUS == ST_CTL_IDLE) {
127  obj->cfg.Axis = axis;
128  }
129 
130  return;
131 } // end of STPOSCTL_setAxis function
132 
136 static inline void STPOSCTL_setSampleTime_sec(ST_POSCTL_Handle handle, _iq24 sampleTime) {
137  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
138 
139  if(obj->STATUS == ST_CTL_IDLE) {
140  obj->cfg.T_sec = sampleTime;
141  }
142 
143  return;
144 } // end of STPOSCTL_setSampleTime_sec function
145 
150  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
151 
152  return obj->cfg.OutMax;
153 } // end of STPOSCTL_getOutputMaximum function
154 
159  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
160 
161  return obj->cfg.OutMin;
162 } // end of STPOSCTL_getOutputMinimum function
163 
164 
169 static inline void STPOSCTL_setOutputMaximums(ST_POSCTL_Handle handle, _iq24 outMax, _iq24 outMin) {
170  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
171 
172  obj->cfg.OutMax = outMax;
173  obj->cfg.OutMin = outMin;
174 
175  return;
176 } // end of STPOSCTL_setOutputMaximums function
177 
181 static inline void STPOSCTL_setVelocityMaximum(ST_POSCTL_Handle handle, _iq24 velMax) {
182  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
183 
184  obj->cfg.VelMax = velMax;
185 
186  return;
187 } // end of STPOSCTL_setVelocityMaximum function
188 
193  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
194 
195  if(obj->STATUS == ST_CTL_IDLE) {
196  obj->cfg.ROMax_mrev = roMax;
197  }
198 
199  return;
200 } // end of STPOSCTL_setPositionRolloverMaximum_mrev function
201 
206 static inline void STPOSCTL_setUnitConversion(ST_POSCTL_Handle handle, float_t baseFreq, uint16_t polePairs) {
207  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
208 
209  if(obj->STATUS == ST_CTL_IDLE) {
210  obj->cfg.mrev_TO_pu = _IQ24(((float_t)polePairs) / baseFreq);
211  }
212 
213  return;
214 } // end of STPOSCTL_setUnitConversion function
215 
219 static inline void STPOSCTL_setRampDisturbanceFlag(ST_POSCTL_Handle handle, bool rampDist) {
220  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
221 
222  if(obj->STATUS == ST_CTL_IDLE) {
223  obj->cfg.RampDist = rampDist;
224  }
225 
226  return;
227 } // end of STPOSCTL_setRampDisturbanceFlag function
228 
233  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
234 
235  if(obj->STATUS == ST_CTL_IDLE) {
236  obj->cfg.PosErrMax_mrev = errMax;
237  }
238 
239  return;
240 } // end of STPOSCTL_setPositionErrorMaximum_mrev function
241 
245 static inline void STPOSCTL_setFilterEnableFlag(ST_POSCTL_Handle handle, bool filterEnable) {
246  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
247 
248  if(obj->STATUS == ST_CTL_IDLE) {
249  obj->cfg.FiltEN = filterEnable;
250  }
251 
252  return;
253 } // end of STPOSCTL_setFilterEnableFlag function
254 
258 static inline void STPOSCTL_setPositionReference_mrev(ST_POSCTL_Handle handle, _iq24 posRef) {
259  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
260 
261  obj->PosRef_mrev = posRef;
262 
263  return;
264 } // end of STPOSCTL_setPositionReference_mrev function
265 
269 static inline void STPOSCTL_setVelocityReference(ST_POSCTL_Handle handle, _iq24 velRef) {
270  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
271 
272  obj->VelRef = velRef;
273 
274  return;
275 } // end of STPOSCTL_setVelocityReference function
276 
280 static inline void STPOSCTL_setAccelerationReference(ST_POSCTL_Handle handle, _iq24 accRef) {
281  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
282 
283  obj->AccRef = accRef;
284 
285  return;
286 } // end of STPOSCTL_setAccelerationReference function
287 
291 static inline void STPOSCTL_setPositionFeedback_mrev(ST_POSCTL_Handle handle, _iq24 posFdb) {
292  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
293 
294  obj->PosFdb_mrev = posFdb;
295 
296  return;
297 } // end of STPOSCTL_setPositionFeedback_mrev function
298 
302 static inline void STPOSCTL_setInertia(ST_POSCTL_Handle handle, _iq24 inertia) {
303  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
304 
305  obj->Inertia = inertia;
306 
307  return;
308 } // end of STPOSCTL_setInertia function
309 
314  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
315 
316  return(obj->Inertia);
317 } // end of STPOSCTL_getInertia function
318 
322 static inline void STPOSCTL_setFriction(ST_POSCTL_Handle handle, _iq24 friction) {
323  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
324 
325  obj->Friction = friction;
326 
327  return;
328 } // end of STPOSCTL_setFriction function
329 
334  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
335 
336  return(obj->Friction);
337 } // end of STPOSCTL_getFriction function
338 
342 static inline void STPOSCTL_setBandwidth_radps(ST_POSCTL_Handle handle, _iq20 bw) {
343  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
344 
345  obj->Bw_radps = bw;
346 
347  return;
348 } // end of STPOSCTL_setBandwidth_radps function
349 
354  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
355 
356  return(obj->Bw_radps);
357 } // end of STPOSCTL_getBandwidth_radps function
358 
362 static inline void STPOSCTL_setEnable(ST_POSCTL_Handle handle, bool enb) {
363  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
364 
365  obj->ENB = enb;
366 
367  return;
368 } // end of STPOSCTL_setEnable function
369 
373 static inline bool STPOSCTL_getEnable(ST_POSCTL_Handle handle) {
374  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
375 
376  return (obj->ENB);
377 } // end of STPOSCTL_getEnable function
378 
382 static inline void STPOSCTL_setTorqueReference(ST_POSCTL_Handle handle, _iq24 out) {
383  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
384 
385  obj->Out = out;
386 
387  return;
388 } // end of STPOSCTL_setTorqueReference function
389 
394  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
395 
396  return (obj->Out);
397 
398 } // end of STPOSCTL_getTorqueReference function
399 
404  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
405 
406  return (obj->STATUS);
407 
408 } // end of STPOSCTL_getStatus function
409 
413 static inline uint16_t STPOSCTL_getErrorID(ST_POSCTL_Handle handle) {
414  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
415 
416  return (obj->ERR_ID);
417 
418 } // end of STPOSCTL_getErrorID function
419 
424  ST_PosCtl_t *obj = (ST_PosCtl_t *)handle;
425 
426  return (obj->PosErr_mrev);
427 
428 } // end of STPOSCTL_getPositionError function
429 
434 ST_POSCTL_Handle STPOSCTL_init(void *pMemory, const size_t numBytes);
435 
438 void STPOSCTL_run(ST_POSCTL_Handle handle);
440 #endif //__SPINTAC_POS_CTL_H__
static _iq20 STPOSCTL_getBandwidth_radps(ST_POSCTL_Handle handle)
Gets the Bandwidth (Bw_radps) for SpinTAC Position Controller.
ST_CTL in busy state.
_iq24 Inertia
System inertia { unit: [PU/(pu/s^2)], value range: positive _IQ24 value }.
_iq24 PosErr_mrev
Position error { unit: [MRev] }.
_iq24 AccRef
Acceleration reference { unit: [pu/s^2] }.
ST_CtlStatus_e
Enumeration for the Control Status states.
static void STPOSCTL_setRampDisturbanceFlag(ST_POSCTL_Handle handle, bool rampDist)
Sets the Ramp Disturbance Flag (cfg.RampDist) for SpinTAC Position Controller.
_iq24 PosFdb_mrev
Position feedback { Unit: [MRev], value range: [-ROMax, ROMax) }.
static void STPOSCTL_setPositionReference_mrev(ST_POSCTL_Handle handle, _iq24 posRef)
Sets the Position Reference (PosRef_mrev) for SpinTAC Position Controller.
void STPOSCTL_run(ST_POSCTL_Handle handle)
Runs the SpinTAC Position Control Function.
Defines the ST_PosCtlCfg_t data.
static void STPOSCTL_setAccelerationReference(ST_POSCTL_Handle handle, _iq24 accRef)
Sets the Acceleration Reference (AccRef) for SpinTAC Position Controller.
_iq24 PosRef_mrev
Position reference { unit: [MRev], value range: [-ROMax, ROMax] }.
ST_Axis_e Axis
Axis ID { ST_AXIS0: axis 0, ST_AXIS1: axis 1}.
_iq24 PosErrMax_mrev
Maximum allowable position error { unit: [MRev], value range (0, ROMax_mrev/2] }. ...
ST_CTL in conf state.
static void STPOSCTL_setSampleTime_sec(ST_POSCTL_Handle handle, _iq24 sampleTime)
Sets the Sample Time (cfg.T_sec) for SpinTAC Position Controller.
static uint16_t STPOSCTL_getErrorID(ST_POSCTL_Handle handle)
Gets the Error value (ERR_ID) for SpinTAC Position Controller.
_iq20 Bw_radps
Controller Bandwidth { unit: [rad/s], value range: [0.01, 1000.0] }.
static ST_CtlStatus_e STPOSCTL_getStatus(ST_POSCTL_Handle handle)
Gets the Status value (STATUS) for SpinTAC Position Controller.
static void STPOSCTL_setPositionRolloverMaximum_mrev(ST_POSCTL_Handle handle, _iq24 roMax)
Sets the Position Rollover Maximum (cfg.ROMax_mrev) for SpinTAC Position Controller.
ST_PosCtlCfg_t cfg
ST_CTL in idle state.
_iq24 mrev_TO_pu
Conversion ratio from mechanical revolution to pu { value range: [0.002, 1]) }.
#define _IQ24(A)
_iq24 T_sec
Sample time { unit: [s], value range: (0, 0.01] }.
static _iq24 STPOSCTL_getTorqueReference(ST_POSCTL_Handle handle)
Gets the Torque (Iq) Reference (Out) for SpinTAC Position Controller.
static bool STPOSCTL_getEnable(ST_POSCTL_Handle handle)
Gets the Enable signal (ENB) for SpinTAC Position Controller.
ST_POSCTL_Handle STPOSCTL_init(void *pMemory, const size_t numBytes)
Initializes the SpinTAC Position Controller object.
bool ENB
Enable bit { false: disable; true: enable }.
static void STPOSCTL_setInertia(ST_POSCTL_Handle handle, _iq24 inertia)
Sets the Inertia (Inertia) for SpinTAC Position Controller.
static void STPOSCTL_setBandwidth_radps(ST_POSCTL_Handle handle, _iq20 bw)
Sets the Bandwidth (Bw_radps) for SpinTAC Position Controller.
Defines the ST_PosCtl_t data.
_iq24 VelMax
Velocity reference signal upper limit { unit: [pu/s], Value range: (0, 1] }.
Second Axis.
long _iq24
static _iq24 STPOSCTL_getInertia(ST_POSCTL_Handle handle)
Gets the Inertia (Inertia) for SpinTAC Position Controller.
static void STPOSCTL_setPositionFeedback_mrev(ST_POSCTL_Handle handle, _iq24 posFdb)
Sets the Position Feedback (PosFdb_mrev) for SpinTAC Position Controller.
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...
static void STPOSCTL_setOutputMaximums(ST_POSCTL_Handle handle, _iq24 outMax, _iq24 outMin)
Sets the Maximum Output (cfg.OutMax) and Minimum Output (cfg.OutMin) for SpinTAC Position Controller...
ST_CtlStatus_e STATUS
Status { ST_CTL_IDLE, ST_CTL_INIT, ST_CTL_CONF, ST_CTL_BUSY }.
static _iq24 STPOSCTL_getOutputMinimum(ST_POSCTL_Handle handle)
Gets the Minimum Output (cfg.OutMin) for SpinTAC Position Controller.
bool FiltEN
Enable low-pass Filter { false: Filter Disabled; true: Filter Enabled }.
_iq24 OutMin
Control signal lower limit { unit: [PU], value range: [-1, OutMax) }.
static void STPOSCTL_setFilterEnableFlag(ST_POSCTL_Handle handle, bool filterEnable)
Sets the Feedback Filter Enable Flag (cfg.FiltEN) for SpinTAC Position Controller.
static void STPOSCTL_setEnable(ST_POSCTL_Handle handle, bool enb)
Sets the Enable signal (ENB) for SpinTAC Position Controller.
static void STPOSCTL_setUnitConversion(ST_POSCTL_Handle handle, float_t baseFreq, uint16_t polePairs)
Sets the Unit Conversion (cfg.mrev_TO_pu) for SpinTAC Position Controller.
_iq24 Friction
Friction Coefficient { unit: [PU/(pu/s)], value range: positive _IQ24 value }.
First Axis.
static void STPOSCTL_setPositionErrorMaximum_mrev(ST_POSCTL_Handle handle, _iq24 errMax)
Sets the Position Error Maximum (cfg.PosErrMax_mrev) for SpinTAC Position Controller.
bool RampDist
Disturbance type { false: Step Disturbance, true: Ramp Disturbance }.
static _iq24 STPOSCTL_getFriction(ST_POSCTL_Handle handle)
Gets the Friction (Friction) for SpinTAC Position Controller.
static void STPOSCTL_setTorqueReference(ST_POSCTL_Handle handle, _iq24 out)
Sets the Torque (Iq) Reference (Out) for SpinTAC Position Controller.
long _iq20
uint16_t ERR_ID
Error ID { 0: no error; others: see error code }.
_iq24 Out
Control output { unit: [PU] }.
static _iq24 STPOSCTL_getOutputMaximum(ST_POSCTL_Handle handle)
Gets the Maximum Output (cfg.OutMax) for SpinTAC Position Controller.
struct _ST_POSCTL_Handle_ * ST_POSCTL_Handle
_iq24 VelRef
Velocity reference { unit: [pu/s] }.
static void STPOSCTL_setVelocityReference(ST_POSCTL_Handle handle, _iq24 velRef)
Sets the Velocity Reference (VelRef) for SpinTAC Position Controller.
static _iq24 STPOSCTL_getPositionError_mrev(ST_POSCTL_Handle handle)
Gets the Position Error (PosErr_mrev) for SpinTAC Position Controller.
static void STPOSCTL_setVelocityMaximum(ST_POSCTL_Handle handle, _iq24 velMax)
Sets the Maximum Velocity (cfg.VelMax) for SpinTAC Position Controller.
static void STPOSCTL_setAxis(ST_POSCTL_Handle handle, ST_Axis_e axis)
Sets the Axis (cfg.Axis) for SpinTAC Position Controller.
_iq24 OutMax
Control signal upper limit { unit: [PU], value range: (-1, 1] }.
static void STPOSCTL_setFriction(ST_POSCTL_Handle handle, _iq24 friction)
Sets the Friction (Friction) for SpinTAC Position Controller.
_iq24 ROMax_mrev
Position Rollover bound { unit: [MRev], value range: [2, 100] }.
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121