~jeremyrcohen/fabinterpreter/Windows_Test

« back to all changes in this revision

Viewing changes to software/Common/Windows/JrKerr/picservo.h

  • Committer: Jeremy Cohen
  • Date: 2011-04-07 18:20:22 UTC
  • Revision ID: jeremyrcohen@gmail.com-20110407182022-3m9sepfpp0k2sab3
Testing QextSerial on Windows

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef PICSERVO_H
2
 
#define PICSERVO_H
3
 
 
4
 
#include <QLibrary>
5
 
 
6
 
typedef unsigned char byte;
7
 
 
8
 
//--------------------- Servo Module specific stuff ---------------------------
9
 
typedef struct _GAINVECT {
10
 
    short int   kp;                             //gain values
11
 
    short int   kd;
12
 
    short int   ki;
13
 
    short int   il;
14
 
    byte                ol;
15
 
    byte                cl;
16
 
    short int   el;
17
 
    byte                sr;
18
 
    byte                dc;
19
 
    byte                sm;
20
 
        } GAINVECT;
21
 
 
22
 
 
23
 
typedef struct _SERVOMOD {
24
 
    long                pos;                    //current position
25
 
    byte                ad;                             //a/d value
26
 
    short int   vel;            //current velocity
27
 
    byte                aux;            //auxilliary status byte
28
 
    long                home;           //home position
29
 
    short int   perror;                 //position error
30
 
    byte                npoints;                //number of points in path buffer
31
 
 
32
 
    //The following data is stored locally for reference
33
 
    long                cmdpos;                 //last commanded position
34
 
    long                cmdvel;                 //last commanded velocity
35
 
    long                cmdacc;                 //last commanded acceleration
36
 
    byte                cmdpwm;                 //last commanded PWM value
37
 
    GAINVECT    gain;
38
 
    long                stoppos;                //motor stop position (used by stop command)
39
 
    byte                stopctrl;               //stop control byte
40
 
    byte                movectrl;               //load_traj control byte
41
 
    byte                ioctrl;                 //I/O control byte
42
 
    byte                homectrl;               //homing control byte
43
 
    byte                ph_adv;                 //phase advance (for ss-drive modules)
44
 
    byte                ph_off;                 //phase offset (for ss-drive modules)
45
 
    long                last_ppoint;    //last path point specified
46
 
    } SERVOMOD;
47
 
 
48
 
 
49
 
//Servo Module Command set:
50
 
#define RESET_POS         0x00  //Reset encoder counter to 0 (0 bytes)
51
 
#define SET_ADDR          0x01  //Set address and group address (2 bytes)
52
 
#define DEF_STAT          0x02  //Define status items to return (1 byte)
53
 
#define READ_STAT         0x03  //Read value of current status items
54
 
#define LOAD_TRAJ         0x04  //Load trahectory date (1 - 14 bytes)
55
 
#define START_MOVE        0x05  //Start pre-loaded trajectory (0 bytes)
56
 
#define SET_GAIN          0x06  //Set servo gain and control parameters (13 or 14)
57
 
#define STOP_MOTOR        0x07  //Stop motor (1 byte)
58
 
#define IO_CTRL           0x08  //Define bit directions and set output (1 byte)
59
 
#define SET_HOMING        0x09  //Define homing mode (1 byte)
60
 
#define SET_BAUD          0x0A  //Set the baud rate (1 byte)
61
 
#define CLEAR_BITS        0x0B  //Save current pos. in home pos. register (0 bytes)
62
 
#define SAVE_AS_HOME  0x0C      //Store the input bytes and timer val (0 bytes)
63
 
#define ADD_PATHPOINT 0x0D  //Adds path points for path mode
64
 
#define NOP                       0x0E  //No operation - returns prev. defined status (0 bytes)
65
 
#define HARD_RESET        0x0F  //RESET - no status is returned
66
 
 
67
 
//Servo Module STATUSITEMS bit definitions:
68
 
#define SEND_POS          0x01  //4 bytes data
69
 
#define SEND_AD           0x02  //1 byte
70
 
#define SEND_VEL          0x04  //2 bytes
71
 
#define SEND_AUX          0x08  //1 byte
72
 
#define SEND_HOME         0x10  //4 bytes
73
 
#define SEND_ID           0x20  //2 bytes
74
 
#define SEND_PERROR       0x40  //2 bytes
75
 
#define SEND_NPOINTS  0x80  //1 byte
76
 
 
77
 
//Servo Module RESET_POS control byte bit definitions:
78
 
//(if no control byte is used, reset is absolute)
79
 
#define REL_HOME          0x01  //Reset position relative to current home position
80
 
#define SET_POS           0x02  //Set the position to a specific value (v10 & >)
81
 
 
82
 
 
83
 
//Servo Module LOAD_TRAJ control byte bit definitions:
84
 
#define LOAD_POS          0x01  //+4 bytes
85
 
#define LOAD_VEL          0x02  //+4 bytes
86
 
#define LOAD_ACC          0x04  //+4 bytes
87
 
#define LOAD_PWM          0x08  //+1 byte
88
 
#define ENABLE_SERVO  0x10  //1 = servo mode, 0 = PWM mode
89
 
#define VEL_MODE          0x20  //1 = velocity mode, 0 = trap. position mode
90
 
#define REVERSE           0x40  //1 = command neg. PWM or vel, 0 = positive
91
 
#define MOVE_REL          0x40  //1 = move relative, 0 = move absolute
92
 
#define START_NOW         0x80  //1 = start now, 0 = wait for START_MOVE command
93
 
 
94
 
//Servo Module STOP_MOTOR control byte bit definitions:
95
 
#define AMP_ENABLE        0x01  //1 = raise amp enable output, 0 = lower amp enable
96
 
#define MOTOR_OFF         0x02  //set to turn motor off
97
 
#define STOP_ABRUPT   0x04      //set to stop motor immediately
98
 
#define STOP_SMOOTH       0x08  //set to decellerate motor smoothly
99
 
#define STOP_HERE         0x10  //set to stop at position (4 add'l data bytes required)
100
 
#define ADV_FEATURE   0x20  //enable features in ver. CMC
101
 
 
102
 
//Servo Module IO_CTRL control byte bit definitions:
103
 
#define SET_OUT1          0x01  //1 = set limit 1 output, 0 = clear limit 1 output
104
 
#define SET_OUT2          0x02  //1 = set limit 2 output, 0 = clear limit 1 output
105
 
#define IO1_IN            0x04  //1 = limit 1 is an input, 0 = limit 1 is an output
106
 
#define IO2_IN            0x08  //1 = limit 2 is an input, 0 = limit 1 is an output
107
 
#define LIMSTOP_OFF   0x04   //turn off motor on limit
108
 
#define LIMSTOP_ABRUPT 0x08  //stop abruptly on limit
109
 
#define THREE_PHASE       0x10  //1 = 3-phase mode, 0 = single PWM channel
110
 
#define ANTIPHASE         0x20  //1 = antiphase (0 = 50% duty cycle), 0 = PWM & dir
111
 
#define FAST_PATH         0x40  //0 = 30 or 60 Hz path execution, 1 = 60 or 120 Hz
112
 
#define STEP_MODE         0x80  //0 = normal operation, 1 = Step & Direction enabled
113
 
 
114
 
//Servo Module SET_HOMING control byte bit definitions:
115
 
#define ON_LIMIT1         0x01  //home on change in limit 1
116
 
#define ON_LIMIT2         0x02  //home on change in limit 2
117
 
#define HOME_MOTOR_OFF  0x04  //turn motor off when homed
118
 
#define ON_INDEX          0x08  //home on change in index
119
 
#define HOME_STOP_ABRUPT 0x10 //stop abruptly when homed
120
 
#define HOME_STOP_SMOOTH 0x20 //stop smoothly when homed
121
 
#define ON_POS_ERR        0x40  //home on excessive position error
122
 
#define ON_CUR_ERR        0x80  //home on overcurrent error
123
 
 
124
 
//Servo Module ADD_PATHPOINT frequency definitions
125
 
#define P_30HZ            30    //30 hz path resolution
126
 
#define P_60HZ            60    //60 hs path resolution
127
 
#define P_120HZ           120   //120 hs path resolution
128
 
 
129
 
//Servo Module HARD_RESET control byte bit definitions (v.10 and higher only):
130
 
#define SAVE_DATA         0x01  //save config. data in EPROM
131
 
#define RESTORE_ADDR  0x02  //restore addresses on power-up
132
 
#define EPU_AMP       0x04      //enable amplifier on power-up
133
 
#define EPU_SERVO     0x08  //enable servo
134
 
#define EPU_STEP          0x10  //enable step & direction mode
135
 
#define EPU_LIMITS    0x20  //enable limit switch protection
136
 
#define EPU_3PH       0x40  //enable 3-phase commutation
137
 
#define EPU_ANTIPHASE 0x80 //enable antiphase PWM
138
 
 
139
 
//Servo Module Status byte bit definitions:
140
 
#define MOVE_DONE         0x01  //set when move done (trap. pos mode), when goal
141
 
                                                        //vel. has been reached (vel mode) or when not servoing
142
 
#define CKSUM_ERROR       0x02  //checksum error in received command
143
 
#define OVERCURRENT       0x04  //set on overcurrent condition (sticky bit)
144
 
#define POWER_ON          0x08  //set when motor power is on
145
 
#define POS_ERR           0x10  //set on excess pos. error (sticky bit)
146
 
#define LIMIT1            0x20  //value of limit 1 input
147
 
#define LIMIT2            0x40  //value of limit 2 input
148
 
#define HOME_IN_PROG  0x80  //set while searching for home, cleared when home found
149
 
 
150
 
//Servo Module Auxilliary status byte bit definitions:
151
 
#define INDEX             0x01  //value of the encoder index signal
152
 
#define POS_WRAP          0x02  //set when 32 bit position counter wraps around
153
 
                                                        //  (sticky bit)
154
 
#define SERVO_ON          0x04  //set when position servo is operating
155
 
#define ACCEL_DONE        0x08  //set when acceleration portion of a move is done
156
 
#define SLEW_DONE         0x10  //set when slew portion of a move is done
157
 
#define SERVO_OVERRUN 0x20  //set if servo takes longer than the specified
158
 
                                                        //servo period to execute
159
 
#define PATH_MODE         0x40  //path mode is enabled (v.5)
160
 
 
161
 
//Load functions from DLL.
162
 
static long (*ServoGetPos)(byte) = reinterpret_cast<long(*)(byte)>(QLibrary::resolve("../Common/Windows/JrKerr/NMCLIB04","ServoGetPos"));
163
 
static byte (*ServoGetAux)(byte) = reinterpret_cast<byte(*)(byte)>(QLibrary::resolve("../Common/Windows/JrKerr/NMCLIB04","ServoGetAux"));
164
 
static BOOL (*ServoResetPos)(byte) = reinterpret_cast<BOOL(*)(byte)>(QLibrary::resolve("../Common/Windows/JrKerr/NMCLIB04","ServoResetPos"));
165
 
static BOOL (*ServoSetGain)(byte,short,short,short,short,byte,byte,short,byte,byte) = reinterpret_cast<BOOL(*)(byte,short,short,short,short,byte,byte,short,byte,byte)>(QLibrary::resolve("../Common/Windows/JrKerr/NMCLIB04","ServoSetGain"));
166
 
static BOOL (*ServoStopMotor)(byte,byte) = reinterpret_cast<BOOL(*)(byte,byte)>(QLibrary::resolve("../Common/Windows/JrKerr/NMCLIB04","ServoStopMotor"));
167
 
static BOOL (*ServoLoadTraj)(byte,byte,long,long,long,byte) = reinterpret_cast<BOOL(*)(byte,byte,long,long,long,byte)>(QLibrary::resolve("../Common/Windows/JrKerr/NMCLIB04","ServoLoadTraj"));
168
 
 
169
 
#endif //ndef PICSERVO_H
 
1
//---------------------------------------------------------------------------
 
2
#ifndef picservoH
 
3
#define picservoH
 
4
//---------------------------------------------------------------------------
 
5
#endif
 
6
//--------------------- Servo Module specific stuff ---------------------------
 
7
 
 
8
typedef unsigned char byte;
 
9
typedef int BOOL;  //0=false, <>0 true
 
10
 
 
11
#define MAXSIOERROR 2
 
12
 
 
13
typedef struct _GAINVECT {
 
14
    short int   kp;                             //gain values
 
15
    short int   kd;
 
16
    short int   ki;
 
17
    short int   il;
 
18
    byte                ol;
 
19
    byte                cl;
 
20
    short int   el;
 
21
    byte                sr;
 
22
    byte                dc;
 
23
        byte            sm;
 
24
        } GAINVECT;
 
25
 
 
26
typedef struct _SERVOMOD {
 
27
    int         pos;                    //current position
 
28
    byte                ad;                             //a/d value
 
29
    short int   vel;            //current velocity
 
30
    byte                aux;            //auxilliary status byte
 
31
    int         home;           //home position
 
32
    short int   perror;                 //position error
 
33
    byte                npoints;                //number of points in path buffer
 
34
 
 
35
    //The following data is stored locally for reference
 
36
    int         cmdpos;                 //last commanded position
 
37
    int         cmdvel;                 //last commanded velocity
 
38
    int         cmdacc;                 //last commanded acceleration
 
39
    byte                cmdpwm;                 //last commanded PWM value
 
40
    GAINVECT    gain;
 
41
    int         stoppos;                //motor stop position (used by stop command)
 
42
    byte                stopctrl;               //stop control byte
 
43
    byte                movectrl;               //load_traj control byte
 
44
    byte                ioctrl;                 //I/O control byte
 
45
    byte                homectrl;               //homing control byte
 
46
    byte                ph_adv;                 //phase advance (for ss-drive modules)
 
47
    byte                ph_off;                 //phase offset (for ss-drive modules)
 
48
    int         last_ppoint;    //last path point specified
 
49
    } SERVOMOD;
 
50
 
 
51
 
 
52
//Servo Module Command set:
 
53
#define RESET_POS         0x00  //Reset encoder counter to 0 (0 bytes)
 
54
#define SET_ADDR          0x01  //Set address and group address (2 bytes)
 
55
#define DEF_STAT          0x02  //Define status items to return (1 byte)
 
56
#define READ_STAT         0x03  //Read value of current status items
 
57
#define LOAD_TRAJ         0x04  //Load trahectory date (1 - 14 bytes)
 
58
#define START_MOVE        0x05  //Start pre-loaded trajectory (0 bytes)
 
59
#define SET_GAIN          0x06  //Set servo gain and control parameters (13 or 14)
 
60
#define STOP_MOTOR        0x07  //Stop motor (1 byte)
 
61
#define IO_CTRL           0x08  //Define bit directions and set output (1 byte)
 
62
#define SET_HOMING        0x09  //Define homing mode (1 byte)
 
63
#define SET_BAUD          0x0A  //Set the baud rate (1 byte)
 
64
#define CLEAR_BITS        0x0B  //Save current pos. in home pos. register (0 bytes)
 
65
#define SAVE_AS_HOME  0x0C      //Store the input bytes and timer val (0 bytes)
 
66
#define ADD_PATHPOINT 0x0D  //Adds path points for path mode
 
67
#define NOP                       0x0E  //No operation - returns prev. defined status (0 bytes)
 
68
#define HARD_RESET        0x0F  //RESET - no status is returned
 
69
 
 
70
//Servo Module RESET_POS control byte bit definitions:
 
71
//(if no control byte is used, reset is absolute)
 
72
#define REL_HOME          0x01  //Reset position relative to current home position
 
73
#define SET_POS           0x02  //Set the position to a specific value (v10 & >)
 
74
 
 
75
//Servo Module STATUSITEMS bit definitions:
 
76
#define SEND_POS          0x01  //4 bytes data
 
77
#define SEND_AD           0x02  //1 byte
 
78
#define SEND_VEL          0x04  //2 bytes
 
79
#define SEND_AUX          0x08  //1 byte
 
80
#define SEND_HOME         0x10  //4 bytes
 
81
#define SEND_ID           0x20  //2 bytes
 
82
#define SEND_PERROR       0x40  //2 bytes
 
83
#define SEND_NPOINTS  0x80  //1 byte
 
84
 
 
85
//Servo Module LOAD_TRAJ control byte bit definitions:
 
86
#define LOAD_POS          0x01  //+4 bytes
 
87
#define LOAD_VEL          0x02  //+4 bytes
 
88
#define LOAD_ACC          0x04  //+4 bytes
 
89
#define LOAD_PWM          0x08  //+1 byte
 
90
#define ENABLE_SERVO  0x10  //1 = servo mode, 0 = PWM mode
 
91
#define VEL_MODE          0x20  //1 = velocity mode, 0 = trap. position mode
 
92
#define REVERSE           0x40  //1 = command neg. PWM or vel, 0 = positive
 
93
#define MOVE_REL          0x40  //1 = move relative, 0 = move absolute
 
94
#define START_NOW         0x80  //1 = start now, 0 = wait for START_MOVE command
 
95
 
 
96
//Servo Module STOP_MOTOR control byte bit definitions:
 
97
#define AMP_ENABLE        0x01  //1 = raise amp enable output, 0 = lower amp enable
 
98
#define MOTOR_OFF         0x02  //set to turn motor off
 
99
#define STOP_ABRUPT   0x04      //set to stop motor immediately
 
100
#define STOP_SMOOTH       0x08  //set to decellerate motor smoothly
 
101
#define STOP_HERE         0x10  //set to stop at position (4 add'l data bytes required)
 
102
#define ADV_FEATURE   0x20  //enable features in ver. CMC
 
103
 
 
104
//Servo Module IO_CTRL control byte bit definitions:
 
105
#define SET_OUT1          0x01  //1 = set limit 1 output, 0 = clear limit 1 output
 
106
#define SET_OUT2          0x02  //1 = set limit 2 output, 0 = clear limit 2 output
 
107
#define IO1_IN            0x04  //1 = limit 1 is an input, 0 = limit 1 is an output
 
108
#define IO2_IN            0x08  //1 = limit 2 is an input, 0 = limit 2 is an output
 
109
#define LIMSTOP_OFF   0x04   //turn off motor on limit
 
110
#define LIMSTOP_ABRUPT 0x08  //stop abruptly on limit
 
111
#define THREE_PHASE       0x10  //1 = 3-phase mode, 0 = single PWM channel
 
112
#define ANTIPHASE         0x20  //1 = antiphase (0 = 50% duty cycle), 0 = PWM & dir
 
113
#define FAST_PATH         0x40  //0 = 30 or 60 Hz path execution, 1 = 60 or 120 Hz
 
114
#define STEP_MODE         0x80  //0 = normal operation, 1 = Step & Direction enabled
 
115
 
 
116
//Servo Module SET_HOMING control byte bit definitions:
 
117
#define ON_LIMIT1         0x01  //home on change in limit 1
 
118
#define ON_LIMIT2         0x02  //home on change in limit 2
 
119
#define HOME_MOTOR_OFF  0x04  //turn motor off when homed
 
120
#define ON_INDEX          0x08  //home on change in index
 
121
#define HOME_STOP_ABRUPT 0x10 //stop abruptly when homed
 
122
#define HOME_STOP_SMOOTH 0x20 //stop smoothly when homed
 
123
#define ON_POS_ERR        0x40  //home on excessive position error
 
124
#define ON_CUR_ERR        0x80  //home on overcurrent error
 
125
 
 
126
//Servo Module ADD_PATHPOINT frequency definitions
 
127
#define P_30HZ            30    //30 hz path resolution
 
128
#define P_60HZ            60    //60 hs path resolution
 
129
#define P_120HZ           120   //120 hs path resolution
 
130
 
 
131
//Servo Module HARD_RESET control byte bit definitions (v.10 and higher only):
 
132
#define SAVE_DATA         0x01  //save config. data in EPROM
 
133
#define RESTORE_ADDR  0x02  //restore addresses on power-up
 
134
#define EPU_AMP       0x04      //enable amplifier on power-up
 
135
#define EPU_SERVO     0x08  //enable servo
 
136
#define EPU_STEP          0x10  //enable step & direction mode
 
137
#define EPU_LIMITS    0x20  //enable limit switch protection
 
138
#define EPU_3PH       0x40  //enable 3-phase commutation
 
139
#define EPU_ANTIPHASE 0x80 //enable antiphase PWM
 
140
 
 
141
//Servo Module Status byte bit definitions:
 
142
#define MOVE_DONE         0x01  //set when move done (trap. pos mode), when goal
 
143
                                                        //vel. has been reached (vel mode) or when not servoing
 
144
#define CKSUM_ERROR       0x02  //checksum error in received command
 
145
#define OVERCURRENT       0x04  //set on overcurrent condition (sticky bit)
 
146
#define POWER_ON          0x08  //set when motor power is on
 
147
#define POS_ERR           0x10  //set on excess pos. error (sticky bit)
 
148
#define LIMIT1            0x20  //value of limit 1 input
 
149
#define LIMIT2            0x40  //value of limit 2 input
 
150
#define HOME_IN_PROG  0x80  //set while searching for home, cleared when home found
 
151
 
 
152
//Servo Module Auxilliary status byte bit definitions:
 
153
#define INDEX             0x01  //value of the encoder index signal
 
154
#define POS_WRAP          0x02  //set when 32 bit position counter wraps around
 
155
                                                        //  (sticky bit)
 
156
#define SERVO_ON          0x04  //set when position servo is operating
 
157
#define ACCEL_DONE        0x08  //set when acceleration portion of a move is done
 
158
#define SLEW_DONE         0x10  //set when slew portion of a move is done
 
159
#define SERVO_OVERRUN 0x20  //set if servo takes longer than the specified
 
160
                                                        //servo period to execute
 
161
#define PATH_MODE         0x40  //path mode is enabled (v.5)
 
162
 
 
163
//Servo module function prototypes:
 
164
 
 
165
//---------------------------------------------------------------------------//
 
166
//  Function Name:  ServoNewMod (Internal Library Function)                  //
 
167
//  Return Value:   Pointer to the new SERVOMOD structure.                   //
 
168
//  Parameters:     None                                                     //
 
169
//  Description:    Creates and initializes a new SERVOMOD structure.        //
 
170
//---------------------------------------------------------------------------//
 
171
extern "C" SERVOMOD * ServoNewMod();
 
172
 
 
173
//---------------------------------------------------------------------------//
 
174
//  Function Name:  ServoGetStat (Internal Library Function)                 //
 
175
//  Return Value:   0=Fail, 1=Success                                        //
 
176
//  Parameters:     addr: module address (1-32)                              //
 
177
//  Description:    Processes and stores returned PIC-SERVO status data.     //
 
178
//---------------------------------------------------------------------------//
 
179
extern "C" BOOL ServoGetStat(byte addr);
 
180
 
 
181
//---------------------------------------------------------------------------//
 
182
//  Function Name:  ServoGetPos                                              //
 
183
//  Return Value:   Returns the current motor position.                      //
 
184
//  Parameters:     addr: module address (1-32)                              //
 
185
//  Description:    Returns the current motor position (stored locally).     //
 
186
//---------------------------------------------------------------------------//
 
187
extern "C" int ServoGetPos(byte addr);
 
188
 
 
189
//---------------------------------------------------------------------------//
 
190
//  Function Name:  ServoGetAD                                               //
 
191
//  Return Value:   Returns the current A/D value.                           //
 
192
//  Parameters:     addr: module address (1-32)                              //
 
193
//  Description:    Returns the current A/D value (stored locally).          //
 
194
//---------------------------------------------------------------------------//
 
195
extern "C" byte ServoGetAD(byte addr);
 
196
 
 
197
//---------------------------------------------------------------------------//
 
198
//  Function Name:  ServoGetVel                                              //
 
199
//  Return Value:   Returns the current motor velocity.                      //
 
200
//  Parameters:     addr: module address (1-32)                              //
 
201
//  Description:    Returns the current motor velocity (stored locally).     //
 
202
//---------------------------------------------------------------------------//
 
203
extern "C" short int ServoGetVel(byte addr);
 
204
 
 
205
//---------------------------------------------------------------------------//
 
206
//  Function Name:  ServoGetAux                                              //
 
207
//  Return Value:   Returns the current auxiliary status byte.               //
 
208
//  Parameters:     addr: module address (1-32)                              //
 
209
//  Description:    Returns the current auxiliary status byte (stored        //
 
210
//                  locally).                                                //
 
211
//---------------------------------------------------------------------------//
 
212
extern "C" byte ServoGetAux(byte addr);
 
213
 
 
214
//---------------------------------------------------------------------------//
 
215
//  Function Name:  ServoGetHome                                             //
 
216
//  Return Value:   Returns the current motor home position.                 //
 
217
//  Parameters:     addr: module address (1-32)                              //
 
218
//  Description:    Returns the current motor home position (stored locally).//
 
219
//---------------------------------------------------------------------------//
 
220
extern "C" int ServoGetHome(byte addr);
 
221
 
 
222
//---------------------------------------------------------------------------//
 
223
//  Function Name:  ServoGetPError                                           //
 
224
//  Return Value:   Returns the servo positioning error.                     //
 
225
//  Parameters:     addr: module address (1-32)                              //
 
226
//  Description:    Returns the servo positioning error (stored locally).    //
 
227
//---------------------------------------------------------------------------//
 
228
extern "C" short int ServoGetPError(byte addr);
 
229
 
 
230
//---------------------------------------------------------------------------//
 
231
//  Function Name:  ServoGetNPoints                                          //
 
232
//  Return Value:   Returns the number of path points remaining.             //
 
233
//  Parameters:     addr: module address (1-32)                              //
 
234
//  Description:    Returns the number of path points remaining (stored      //
 
235
//                  locally).                                                //
 
236
//---------------------------------------------------------------------------//
 
237
extern "C" byte ServoGetNPoints(byte addr);
 
238
 
 
239
//---------------------------------------------------------------------------//
 
240
//  Function Name:  ServoGetCmdPos                                           //
 
241
//  Return Value:   Returns the most recently issued command position.       //
 
242
//  Parameters:     addr: module address (1-32)                              //
 
243
//  Description:    Returns the most recently issued command position.       //
 
244
//---------------------------------------------------------------------------//
 
245
extern "C" int ServoGetCmdPos(byte addr);
 
246
 
 
247
//---------------------------------------------------------------------------//
 
248
//  Function Name:  ServoGetCmdVel                                           //
 
249
//  Return Value:   Returns the most recently issued command velocity.       //
 
250
//  Parameters:     addr: module address (1-32)                              //
 
251
//  Description:    Returns the most recently issued command velocity.       //
 
252
//---------------------------------------------------------------------------//
 
253
extern "C" int ServoGetCmdVel(byte addr);
 
254
 
 
255
//---------------------------------------------------------------------------//
 
256
//  Function Name:  ServoGetCmdAcc                                           //
 
257
//  Return Value:   Returns the most recently issued command acceleration.   //
 
258
//  Parameters:     addr: module address (1-32)                              //
 
259
//  Description:    Returns the most recently issued command acceleration.   //
 
260
//---------------------------------------------------------------------------//
 
261
extern "C" int ServoGetCmdAcc(byte addr);
 
262
 
 
263
//---------------------------------------------------------------------------//
 
264
//  Function Name:  ServoGetStopPos                                          //
 
265
//  Return Value:   Returns the most recently issued stop position.          //
 
266
//  Parameters:     addr: module address (1-32)                              //
 
267
//  Description:    Returns the most recently issued stop position (by a     //
 
268
//                  ServoStopHere() command).                                //
 
269
//---------------------------------------------------------------------------//
 
270
extern "C" int ServoGetStopPos(byte addr);
 
271
 
 
272
//---------------------------------------------------------------------------//
 
273
//  Function Name:  ServoGetCmdPwm                                           //
 
274
//  Return Value:   Returns the most recently issued command PWM.            //
 
275
//  Parameters:     addr: module address (1-32)                              //
 
276
//  Description:    Returns the most recently issued command PWM.            //
 
277
//---------------------------------------------------------------------------//
 
278
extern "C" byte ServoGetCmdPwm(byte addr);
 
279
 
 
280
//---------------------------------------------------------------------------//
 
281
//  Function Name:  ServoGetMoveCtrl                                         //
 
282
//  Return Value:   Returns most recently issued move command control byte.  //
 
283
//  Parameters:     addr: module address (1-32)                              //
 
284
//  Description:    Returns the most recently issued move command control    //
 
285
//                  byte.                                                    //
 
286
//---------------------------------------------------------------------------//
 
287
extern "C" byte ServoGetMoveCtrl(byte addr);
 
288
 
 
289
//---------------------------------------------------------------------------//
 
290
//  Function Name:  ServoGetStopCtrl                                         //
 
291
//  Return Value:   Returns most recently issued stop command control byte.  //
 
292
//  Parameters:     addr: module address (1-32)                              //
 
293
//  Description:    Returns the most recently issued stop command control    //
 
294
//                  byte.                                                    //
 
295
//---------------------------------------------------------------------------//
 
296
extern "C" byte ServoGetStopCtrl(byte addr);
 
297
 
 
298
//---------------------------------------------------------------------------//
 
299
//  Function Name:  ServoGetHomeCtrl                                         //
 
300
//  Return Value:   Returns most recently issued home command control byte.  //
 
301
//  Parameters:     addr: module address (1-32)                              //
 
302
//  Description:    Returns the most recently issued home command control    //
 
303
//                  byte.                                                    //
 
304
//---------------------------------------------------------------------------//
 
305
extern "C" byte ServoGetHomeCtrl(byte addr);
 
306
 
 
307
//---------------------------------------------------------------------------//
 
308
//  Function Name:  ServoGetIoCtrl                                           //
 
309
//  Return Value:   Returns most recently issued I/O command control byte.   //
 
310
//  Parameters:     addr: module address (1-32)                              //
 
311
//  Description:    Returns the most recently issued I/O command control     //
 
312
//                  byte.                                                    //
 
313
//---------------------------------------------------------------------------//
 
314
extern "C" byte ServoGetIoCtrl(byte addr);
 
315
 
 
316
extern "C" byte ServoGetPhAdv(byte addr);
 
317
extern "C" byte ServoGetPhOff(byte addr);
 
318
 
 
319
//---------------------------------------------------------------------------//
 
320
//  Function Name:  ServoGetGain                                             //
 
321
//  Return Value:   None                                                     //
 
322
//  Parameters:     addr: module address (1-32)                              //
 
323
//                  kp: position gain Kp                                     //
 
324
//                  kd: derivative gain Kd                                   //
 
325
//                  ki: integral gain Ki                                     //
 
326
//                  il: integration limit IL                                 //
 
327
//                  ol: output limit OL                                      //
 
328
//                  cl: current limit CL                                     //
 
329
//                  el: position error limit EL                              //
 
330
//                  sr: servo rate divisor SR                                //
 
331
//                  dc: amplifier deadband compenstation DB                  //
 
332
//  Description:    Returns the most recently issued servo gain values for   //
 
333
//                  a PIC-SERVO module.  For PIC-SERVO SC modules, use       //
 
334
//                  ServoGetGain2().                                         //
 
335
//---------------------------------------------------------------------------//
 
336
extern "C" void ServoGetGain(byte addr, short int * kp, short int * kd, short int * ki,
 
337
                                  short int * il, byte * ol, byte * cl, short int * el,
 
338
                  byte * sr, byte * dc);
 
339
 
 
340
//---------------------------------------------------------------------------//
 
341
//  Function Name:  ServoSetGain                                             //
 
342
//  Return Value:   0=Fail, 1=Success                                        //
 
343
//  Parameters:     addr: module address (1-32)                              //
 
344
//                  kp: Position gain Kp (0 - +32,767)                       //
 
345
//                  kd: Derivative gain Kd (0 - +32,767)                     //
 
346
//                  ki: Integral gain Ki (0 - +32,767)                       //
 
347
//                  ol: Output limit OL (0 - 255)                            //
 
348
//                  cl: Current limit CL (0 - 255)                           //
 
349
//                     (odd values: CUR_SENSE proportional to motor current) //
 
350
//                     (even values: CUR_SENSE inv. prop. to motor current)  //
 
351
//                  el: Position error limit EL (0 - +32,767)                //
 
352
//                  sr: Servo rate divisor SR (1 - 255)                      //
 
353
//                  dc: Amplifier deadband compenstation DB (0 - 255)        //
 
354
//  Description:    Sets most of the non-motion related operating parameters //
 
355
//                  of the PIC-SERVO.  New applications should use           //
 
356
//                  ServoSetGain2() for all versions of PIC-SERVO.           //
 
357
//---------------------------------------------------------------------------//
 
358
extern "C" BOOL ServoSetGain(byte addr, short int kp, short int kd, short int ki,
 
359
                                  short int il, byte ol, byte cl, short int el,
 
360
                  byte sr, byte dc);
 
361
 
 
362
//---------------------------------------------------------------------------//
 
363
//  Function Name:  ServoGetGain2                                            //
 
364
//  Return Value:   None                                                     //
 
365
//  Parameters:     addr: module address (1-32)                              //
 
366
//                  kp: position gain Kp                                     //
 
367
//                  kd: derivative gain Kd                                   //
 
368
//                  ki: integral gain Ki                                     //
 
369
//                  il: integration limit IL                                 //
 
370
//                  ol: output limit OL                                      //
 
371
//                  cl: current limit CL                                     //
 
372
//                  el: position error limit EL                              //
 
373
//                  sr: servo rate divisor SR                                //
 
374
//                  dc: amplifier deadband compenstation DB                  //
 
375
//                  sm: step rate multiplier SM                              //
 
376
//  Description:    Returns the most recently issued servo gain values for   //
 
377
//                  a PIC-SERVO SC module. For non-PIC-SERVO SC modules,     //
 
378
//                  use ServoGetGain().                                      //
 
379
//---------------------------------------------------------------------------//
 
380
extern "C" void ServoGetGain2(byte addr, short int * kp, short int * kd, short int * ki,
 
381
                                                                short int * il, byte * ol, byte * cl, short int * el,
 
382
                                                                byte * sr, byte * dc, byte * sm);
 
383
 
 
384
//---------------------------------------------------------------------------//
 
385
//  Function Name:  ServoSetGain2                                            //
 
386
//  Return Value:   0=Fail, 1=Success                                        //
 
387
//  Parameters:     addr: module address (1-32)                              //
 
388
//                  kp: Position gain Kp (0 - +32,767)                       //
 
389
//                  kd: Derivative gain Kd (0 - +32,767)                     //
 
390
//                  ki: Integral gain Ki (0 - +32,767)                       //
 
391
//                  ol: Output limit OL (0 - 255)                            //
 
392
//                  cl: Current limit CL (0 - 255)                           //
 
393
//                     (odd values: CUR_SENSE proportional to motor current) //
 
394
//                     (even values: CUR_SENSE inv. prop. to motor current)  //
 
395
//                  el: Position error limit EL (0 - +32,767)                //
 
396
//                  sr: Servo rate divisor SR (1 - 255)                      //
 
397
//                  dc: Amplifier deadband compenstation DB (0 - 255)        //
 
398
//                  sm: Step rate multiplier (1 - 255)                       //
 
399
//  Description:    Sets most of the non-motion related operating parameters //
 
400
//                  of the PIC-SERVO.  New applications should use this      //
 
401
//                  version of the Set Gain command (rather than             //
 
402
//                  ServoSetGain()) for all versions of the PIC-SERVO.       //
 
403
//---------------------------------------------------------------------------//
 
404
extern "C" BOOL ServoSetGain2(byte addr, short int kp, short int kd, short int ki,
 
405
                                                           short int il, byte ol, byte cl, short int el,
 
406
                                                           byte sr, byte dc, byte sm);
 
407
 
 
408
//---------------------------------------------------------------------------//
 
409
//  Function Name:  ServoResetPos                                            //
 
410
//  Return Value:   0=Fail, 1=Success                                        //
 
411
//  Parameters:     addr: module addr (1-32)                                 //
 
412
//  Description:    Resets the position counter to zero.                     //
 
413
//---------------------------------------------------------------------------//
 
414
extern "C" BOOL ServoResetPos(byte addr);
 
415
 
 
416
//---------------------------------------------------------------------------//
 
417
//  Function Name:  ServoResetRelHome                                        //
 
418
//  Return Value:   0=Fail, 1=Success                                        //
 
419
//  Parameters:     addr: module address (1-32)                              //
 
420
//  Description:    Resets the position of a module relative to the home     //
 
421
//                  position register (home position is now zero position).  //
 
422
//---------------------------------------------------------------------------//
 
423
extern "C" BOOL ServoResetRelHome(byte addr);
 
424
 
 
425
//---------------------------------------------------------------------------//
 
426
//  Function Name:  ServoSetPos                                              //
 
427
//  Return Value:   0=Fail, 1=Success                                        //
 
428
//  Parameters:     addr: module address (1-32)                              //
 
429
//                  pos: position (-2,147,483,648 - +2,147,483,647)          //
 
430
//  Description:    Sets the module position to the specified value.         //
 
431
//---------------------------------------------------------------------------//
 
432
extern "C" BOOL ServoSetPos(byte addr, int pos);
 
433
 
 
434
//---------------------------------------------------------------------------//
 
435
//  Function Name:  ServoClearBits                                           //
 
436
//  Return Value:   0=Fail, 1=Success                                        //
 
437
//  Parameters:     addr: module address (1-32)                              //
 
438
//  Description:    Clears the latched status bits (OVERCURRENT and          //
 
439
//                  POS_ERROR bits in status byte, and POS_WRAP and          //
 
440
//                  SERVO_OVERRUN bits in auxiliary status byte).            //
 
441
//---------------------------------------------------------------------------//
 
442
extern "C" BOOL ServoClearBits(byte addr);
 
443
 
 
444
//---------------------------------------------------------------------------//
 
445
//  Function Name:  ServoStopMotor                                           //
 
446
//  Return Value:   0=Fail, 1=Success                                        //
 
447
//  Parameters:     addr: module address (1-32)                              //
 
448
//                  mode: logical OR of stop mode bits                       //
 
449
//  Description:    Stop the motor in the manner specified by mode.          //
 
450
//---------------------------------------------------------------------------//
 
451
extern "C" BOOL ServoStopMotor(byte addr, byte mode);
 
452
 
 
453
//---------------------------------------------------------------------------//
 
454
//  Function Name:  ServoStopHere                                            //
 
455
//  Return Value:   0=Fail, 1=Success                                        //
 
456
//  Parameters:     addr: module address (1-32)                              //
 
457
//                  mode: logical OR of the stop mode bits (see picservo.h)  //
 
458
//                  pos: unprofiled command position                         //
 
459
//  Description:    Stop the motor at the specified position.                //
 
460
//---------------------------------------------------------------------------//
 
461
extern "C" BOOL ServoStopHere(byte addr, byte mode, int pos);
 
462
 
 
463
//---------------------------------------------------------------------------//
 
464
//  Function Name:  ServoSetIoCtrl                                           //
 
465
//  Return Value:   0=Fail, 1=Success                                        //
 
466
//  Parameters:     addr: module address (1-32)                              //
 
467
//                  mode: logical OR of I/O control bits (see picservo.h)    //
 
468
//  Description:    Controls the configuration of the LIMIT1 and LIMIT2      //
 
469
//                  I/O pins, as well as other miscellaneous functions.      //
 
470
//                  CAUTION: Use extreme care in setting the parameters for  //
 
471
//                  this command - incorrect settings could damage your      //
 
472
//                  amplifier or the PIC-SERVO chip.                         //
 
473
//---------------------------------------------------------------------------//
 
474
extern "C" BOOL ServoSetIoCtrl(byte addr, byte mode);
 
475
 
 
476
//---------------------------------------------------------------------------//
 
477
//  Function Name:  ServoLoadTraj                                            //
 
478
//  Return Value:   0=Fail, 1=Success                                        //
 
479
//  Parameters:     addr: module address (1-32)                              //
 
480
//                  mode: logical OR of the load trajectory mode bits        //
 
481
//                        (see picservo.h)                                   //
 
482
//                  pos: Position data if LOAD_POS bit of mode is set        //
 
483
//                       (-2,147,483,648 - +2,147,483,647)                   //
 
484
//                  vel: Velocity data is LOAD_VEL bit of mode is set        //
 
485
//                       (0 - +83,886,080)                                   //
 
486
//                  acc: Acceleration data is LOAD_ACC bit of mode is set    //
 
487
//                       (0 - +2,147,483,647)                                //
 
488
//                  pwm: PWM data is LOAD_PWM bit of mode is set (0 - +255)  //
 
489
//  Description:    Loads motion trajectory and PWM information.             //
 
490
//---------------------------------------------------------------------------//
 
491
extern "C" BOOL ServoLoadTraj(byte addr, byte mode, int pos, int vel, int acc, byte pwm);
 
492
 
 
493
//---------------------------------------------------------------------------//
 
494
//  Function Name:  ServoInitPath                                            //
 
495
//  Return Value:   None                                                     //
 
496
//  Parameters:     addr: module address (1-32)                              //
 
497
//  Description:    Initializes the starting point of a path to the current  //
 
498
//                  motor position.                                          //
 
499
//---------------------------------------------------------------------------//
 
500
extern "C" void ServoInitPath(byte addr);
 
501
 
 
502
//---------------------------------------------------------------------------//
 
503
//  Function Name:  ServoAddPathPoints                                       //
 
504
//  Return Value:   0=Fail, 1=Success                                        //
 
505
//  Parameters:     addr: module address (1-32)                              //
 
506
//                  npoints: number of points in list (1-7)                  //
 
507
//                  path: path points list of absolute position data         //
 
508
//                  freq: path point frequency (P_30HZ, P_60HZ, P-120HZ)     //
 
509
//  Description:    Adds a set of path points for path mode operation.  Use  //
 
510
//                  ServoStartPathMode() to start path mode.                 //
 
511
//---------------------------------------------------------------------------//
 
512
extern "C" BOOL ServoAddPathpoints(byte addr, int npoints, int *path, int freq);
 
513
 
 
514
//---------------------------------------------------------------------------//
 
515
//  Function Name:  ServoStartPathMode                                       //
 
516
//  Return Value:   0=Fail, 1=Success                                        //
 
517
//  Parameters:     groupaddr: module addr( 1-32) or group addr (0x80-0xFF)  //
 
518
//                  groupleader: group leader address                        //
 
519
//                    if groupaddr individual use: groupleader=groupaddr     //
 
520
//                    if groupaddr group use: groupleader=group leader addr  //
 
521
//                    (if no group leader use: groupleader = 0)              //
 
522
//  Description:    Starts execution of the path loaded into the internal    //
 
523
//                  path point buffer.                                       //
 
524
//---------------------------------------------------------------------------//
 
525
extern "C" BOOL ServoStartPathMode(byte groupaddr, byte groupleader);
 
526
 
 
527
//---------------------------------------------------------------------------//
 
528
//  Function Name:  ServoStartMove                                           //
 
529
//  Return Value:   0=Fail, 1=Success                                        //
 
530
//  Parameters:     groupaddr: module addr (1-32) or group addr (0x80-0xFF)  //
 
531
//                  groupleader: group leader address                        //
 
532
//                    if groupaddr individual use: groupleader=groupaddr     //
 
533
//                    if groupaddr group use: groupleader=group leader addr  //
 
534
//                    (if no group leader use: groupleader = 0)              //
 
535
//  Description:    Synchronously start motions that have been preloaded     //
 
536
//                  using ServoLoadTraj().                                   //
 
537
//---------------------------------------------------------------------------//
 
538
extern "C" BOOL ServoStartMove(byte groupaddr, byte groupleader);
 
539
 
 
540
//---------------------------------------------------------------------------//
 
541
//  Function Name:  ServoSetHoming                                           //
 
542
//  Return Value:   0=Fail, 1=Success                                        //
 
543
//  Parameters:     addr: module address (1-32)                              //
 
544
//                  mode: logical OR of the homing mode bits (see picservo.h)//
 
545
//  Description:    Sets homing mode parameters for capturing the home       //
 
546
//                  position.                                                //
 
547
//---------------------------------------------------------------------------//
 
548
extern "C" BOOL ServoSetHoming(byte addr, byte mode);
 
549
 
 
550
extern "C" BOOL ServoSetPhase(byte addr, int padvance, int poffset, int maxpwm);
 
551
 
 
552
//---------------------------------------------------------------------------//
 
553
//  Function Name:  ServoHardReset                                           //
 
554
//  Return Value:   0=Fail, 1=Success                                        //
 
555
//  Parameters:     addr: module address (1-32)                              //
 
556
//                  mode: logical OR of reset control bits (see picservo.h)  //
 
557
//  Description:    Reset the controller to it's power-up state and          //
 
558
//                  optionally store configuration data in EEPROM.           //
 
559
//                  (Only valid for PIC-SERVO SC - v.10 and greater)         //
 
560
//---------------------------------------------------------------------------//
 
561
extern "C" BOOL ServoHardReset(byte addr, byte mode);
 
562
 
 
563