2024-05-22 11:38:43 -05:00
|
|
|
|
/* File: devMD90.cc */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
/* Device Support Routines for motor */
|
|
|
|
|
/*
|
|
|
|
|
* Original Author: Mark Rivers
|
|
|
|
|
* Date: 02-24-2002
|
|
|
|
|
*
|
|
|
|
|
* Modification Log:
|
|
|
|
|
* -----------------
|
|
|
|
|
* .00 02-24-2002 mlr initialized from devPM304.c
|
|
|
|
|
* .01 05-23-2003 rls Converted to R3.14.x.
|
2004-02-20 00:12:28 +00:00
|
|
|
|
* .02 02-19-2004 mlr Bug fix when not sending anything
|
2003-05-27 13:39:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define VERSION 1.00
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include "motorRecord.h"
|
|
|
|
|
#include "motor.h"
|
|
|
|
|
#include "motordevCom.h"
|
2024-05-22 11:38:43 -05:00
|
|
|
|
#include "drvMD90.h"
|
2003-05-27 13:39:41 +00:00
|
|
|
|
#include "epicsExport.h"
|
|
|
|
|
|
|
|
|
|
#define STATIC static
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
extern struct driver_table MD90_access;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
#define NINT(f) (long)((f)>0 ? (f)+0.5 : (f)-0.5)
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
volatile int devMD90Debug = 0;
|
|
|
|
|
extern "C" {epicsExportAddress(int, devMD90Debug);}
|
2011-11-29 20:50:00 +00:00
|
|
|
|
|
|
|
|
|
static inline void Debug(int level, const char *format, ...) {
|
|
|
|
|
#ifdef DEBUG
|
2024-05-22 11:38:43 -05:00
|
|
|
|
if (level < devMD90Debug)
|
2011-11-29 20:50:00 +00:00
|
|
|
|
{
|
|
|
|
|
va_list pVar;
|
|
|
|
|
va_start(pVar, format);
|
|
|
|
|
vprintf(format, pVar);
|
|
|
|
|
va_end(pVar);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
/* Debugging levels:
|
2024-05-22 11:38:43 -05:00
|
|
|
|
* devMD90Debug >= 3 Print new part of command and command string so far
|
|
|
|
|
* at the end of MD90_build_trans
|
2003-05-27 13:39:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
/* ----------------Create the dsets for devMD90----------------- */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
STATIC struct driver_table *drvtabptr;
|
2024-05-22 11:38:43 -05:00
|
|
|
|
STATIC long MD90_init(int);
|
|
|
|
|
STATIC long MD90_init_record(void *);
|
|
|
|
|
STATIC long MD90_start_trans(struct motorRecord *);
|
|
|
|
|
STATIC RTN_STATUS MD90_build_trans(motor_cmnd, double *, struct motorRecord *);
|
|
|
|
|
STATIC RTN_STATUS MD90_end_trans(struct motorRecord *);
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
struct motor_dset devMD90 =
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
2024-05-22 11:38:43 -05:00
|
|
|
|
{8, NULL, (DEVSUPFUN) MD90_init, (DEVSUPFUN) MD90_init_record, NULL},
|
2003-05-27 13:39:41 +00:00
|
|
|
|
motor_update_values,
|
2024-05-22 11:38:43 -05:00
|
|
|
|
MD90_start_trans,
|
|
|
|
|
MD90_build_trans,
|
|
|
|
|
MD90_end_trans
|
2003-05-27 13:39:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
extern "C" {epicsExportAddress(dset,devMD90);}
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* --------------------------- program data --------------------- */
|
|
|
|
|
/* This table is used to define the command types */
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
static msg_types MD90_table[] = {
|
2003-05-27 13:39:41 +00:00
|
|
|
|
MOTION, /* MOVE_ABS */
|
|
|
|
|
MOTION, /* MOVE_REL */
|
|
|
|
|
MOTION, /* HOME_FOR */
|
|
|
|
|
MOTION, /* HOME_REV */
|
|
|
|
|
IMMEDIATE, /* LOAD_POS */
|
|
|
|
|
IMMEDIATE, /* SET_VEL_BASE */
|
|
|
|
|
IMMEDIATE, /* SET_VELOCITY */
|
|
|
|
|
IMMEDIATE, /* SET_ACCEL */
|
|
|
|
|
IMMEDIATE, /* GO */
|
|
|
|
|
IMMEDIATE, /* SET_ENC_RATIO */
|
|
|
|
|
INFO, /* GET_INFO */
|
|
|
|
|
MOVE_TERM, /* STOP_AXIS */
|
|
|
|
|
VELOCITY, /* JOG */
|
|
|
|
|
IMMEDIATE, /* SET_PGAIN */
|
|
|
|
|
IMMEDIATE, /* SET_IGAIN */
|
|
|
|
|
IMMEDIATE, /* SET_DGAIN */
|
|
|
|
|
IMMEDIATE, /* ENABLE_TORQUE */
|
|
|
|
|
IMMEDIATE, /* DISABL_TORQUE */
|
|
|
|
|
IMMEDIATE, /* PRIMITIVE */
|
|
|
|
|
IMMEDIATE, /* SET_HIGH_LIMIT */
|
2004-02-20 00:12:28 +00:00
|
|
|
|
IMMEDIATE, /* SET_LOW_LIMIT */
|
|
|
|
|
VELOCITY /* JOB_VELOCITY */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
static struct board_stat **MD90_cards;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
/* --------------------------- program data --------------------- */
|
|
|
|
|
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
/* initialize device support for MD90 stepper motor */
|
|
|
|
|
STATIC long MD90_init(int after)
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
|
|
|
|
long rtnval;
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
Debug(5, "MD90_init: entry\n");
|
2018-10-10 10:26:19 -05:00
|
|
|
|
if (!after)
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
2024-05-22 11:38:43 -05:00
|
|
|
|
drvtabptr = &MD90_access;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
(drvtabptr->init)();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
rtnval = motor_init_com(after, *drvtabptr->cardcnt_ptr, drvtabptr, &MD90_cards);
|
|
|
|
|
Debug(5, "MD90_init: exit\n");
|
2003-05-27 13:39:41 +00:00
|
|
|
|
return(rtnval);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* initialize a record instance */
|
2024-05-22 11:38:43 -05:00
|
|
|
|
STATIC long MD90_init_record(void *arg)
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
|
|
|
|
struct motorRecord *mr = (struct motorRecord *) arg;
|
|
|
|
|
long rtnval;
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
Debug(5, "MD90_init_record: entry\n");
|
2003-05-27 13:39:41 +00:00
|
|
|
|
rtnval = motor_init_record_com(mr, *drvtabptr->cardcnt_ptr,
|
2024-05-22 11:38:43 -05:00
|
|
|
|
drvtabptr, MD90_cards);
|
2003-05-27 13:39:41 +00:00
|
|
|
|
return(rtnval);
|
2024-05-22 11:38:43 -05:00
|
|
|
|
Debug(5, "MD90_init_record: exit\n");
|
2003-05-27 13:39:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* start building a transaction */
|
2024-05-22 11:38:43 -05:00
|
|
|
|
STATIC long MD90_start_trans(struct motorRecord *mr)
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
|
|
|
|
return(OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* end building a transaction */
|
2024-05-22 11:38:43 -05:00
|
|
|
|
STATIC RTN_STATUS MD90_end_trans(struct motorRecord *mr)
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
|
|
|
|
return(OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a part to the transaction */
|
2024-05-22 11:38:43 -05:00
|
|
|
|
STATIC RTN_STATUS MD90_build_trans(motor_cmnd command, double *parms, struct motorRecord *mr)
|
2003-05-27 13:39:41 +00:00
|
|
|
|
{
|
|
|
|
|
struct motor_trans *trans = (struct motor_trans *) mr->dpvt;
|
|
|
|
|
struct mess_node *motor_call;
|
|
|
|
|
struct controller *brdptr;
|
2024-05-22 11:38:43 -05:00
|
|
|
|
struct MD90controller *cntrl;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
char buff[30];
|
|
|
|
|
int axis, card;
|
|
|
|
|
RTN_STATUS rtnval;
|
|
|
|
|
double dval;
|
|
|
|
|
long ival;
|
2004-02-20 00:12:28 +00:00
|
|
|
|
bool send;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
2004-02-20 00:12:28 +00:00
|
|
|
|
send = true;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
rtnval = OK;
|
|
|
|
|
buff[0] = '\0';
|
2004-06-24 19:52:09 +00:00
|
|
|
|
/* Protect against NULL pointer with WRTITE_MSG(GO/STOP_AXIS/GET_INFO, NULL). */
|
|
|
|
|
dval = (parms == NULL) ? 0.0 : *parms;
|
|
|
|
|
ival = NINT(dval);
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MD90_cards);
|
|
|
|
|
Debug(5, "MD90_build_trans: entry, motor_start_trans_com=%d\n", rtnval);
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
motor_call = &(trans->motor_call);
|
2024-05-22 11:38:43 -05:00
|
|
|
|
motor_call->type = MD90_table[command];
|
2003-05-27 13:39:41 +00:00
|
|
|
|
card = motor_call->card;
|
|
|
|
|
axis = motor_call->signal;
|
|
|
|
|
brdptr = (*trans->tabptr->card_array)[card];
|
2024-05-22 11:38:43 -05:00
|
|
|
|
Debug(5, "MD90_build_trans: axis=%d, command=%d\n", axis, command);
|
2003-05-27 13:39:41 +00:00
|
|
|
|
if (brdptr == NULL)
|
|
|
|
|
return(rtnval = ERROR);
|
|
|
|
|
|
2024-05-22 11:38:43 -05:00
|
|
|
|
cntrl = (struct MD90controller *) brdptr->DevicePrivate;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (trans->state != BUILD_STATE)
|
|
|
|
|
return(rtnval = ERROR);
|
|
|
|
|
|
|
|
|
|
if (command == PRIMITIVE && mr->init != NULL && strlen(mr->init) != 0)
|
|
|
|
|
{
|
|
|
|
|
strcpy(motor_call->message, mr->init);
|
|
|
|
|
rtnval = motor_end_trans_com(mr, drvtabptr);
|
2024-05-22 11:38:43 -05:00
|
|
|
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MD90_cards);
|
|
|
|
|
motor_call->type = MD90_table[command];
|
2003-05-27 13:39:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
|
{
|
|
|
|
|
case MOVE_ABS:
|
|
|
|
|
case MOVE_REL:
|
|
|
|
|
case HOME_FOR:
|
|
|
|
|
case HOME_REV:
|
|
|
|
|
case JOG:
|
|
|
|
|
if (strlen(mr->prem) != 0)
|
|
|
|
|
{
|
|
|
|
|
strcpy(motor_call->message, mr->prem);
|
2004-02-20 00:12:28 +00:00
|
|
|
|
rtnval = motor_end_trans_com(mr, drvtabptr);
|
2024-05-22 11:38:43 -05:00
|
|
|
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MD90_cards);
|
|
|
|
|
motor_call->type = MD90_table[command];
|
2003-05-27 13:39:41 +00:00
|
|
|
|
}
|
|
|
|
|
if (strlen(mr->post) != 0)
|
|
|
|
|
motor_call->postmsgptr = (char *) &mr->post;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
|
{
|
|
|
|
|
case MOVE_ABS:
|
|
|
|
|
sprintf(motor_call->message, "#%02dG%+ld", axis, ival);
|
|
|
|
|
break;
|
|
|
|
|
case MOVE_REL:
|
|
|
|
|
sprintf(motor_call->message, "#%02dI%+ld", axis, ival);
|
|
|
|
|
break;
|
|
|
|
|
case HOME_FOR:
|
|
|
|
|
sprintf(motor_call->message, "#%02dH+", axis);
|
|
|
|
|
break;
|
|
|
|
|
case HOME_REV:
|
|
|
|
|
sprintf(motor_call->message, "#%02dH-", axis);
|
|
|
|
|
break;
|
|
|
|
|
case LOAD_POS:
|
|
|
|
|
sprintf(motor_call->message, "#%02dP=%+ld", axis, ival);
|
|
|
|
|
break;
|
|
|
|
|
case SET_VEL_BASE:
|
2004-02-20 00:12:28 +00:00
|
|
|
|
send=false;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
trans->state = IDLE_STATE;
|
2024-05-22 11:38:43 -05:00
|
|
|
|
break; /* MD90 does not use base velocity */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
case SET_VELOCITY:
|
|
|
|
|
ival = (int) (fabs(115200./dval) + 0.5);
|
|
|
|
|
if (ival < 2) ival=2;
|
|
|
|
|
if (ival > 255) ival = 255;
|
|
|
|
|
sprintf(motor_call->message, "#%02dV=%ld", axis, ival);
|
|
|
|
|
break;
|
|
|
|
|
case SET_ACCEL:
|
|
|
|
|
/* dval is acceleration in steps/sec/sec */
|
2024-05-22 11:38:43 -05:00
|
|
|
|
/* MD-90 is programmed with Ramp Index (R) where: */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
/* dval (steps/sec/sec) = 720,000/(256-R) */
|
|
|
|
|
/* or R=256-(720,000/dval) */
|
|
|
|
|
ival = (int) (256-(720000./dval)+0.5);
|
|
|
|
|
if (ival < 1) ival=1;
|
|
|
|
|
if (ival > 255) ival=255;
|
|
|
|
|
sprintf(motor_call->message, "#%02dR=%ld", axis, ival);
|
|
|
|
|
break;
|
|
|
|
|
case GO:
|
|
|
|
|
/*
|
2024-05-22 11:38:43 -05:00
|
|
|
|
* The MD90 starts moving immediately on move commands, GO command
|
2003-05-27 13:39:41 +00:00
|
|
|
|
* does nothing
|
|
|
|
|
*/
|
2004-02-20 00:12:28 +00:00
|
|
|
|
send=false;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
trans->state = IDLE_STATE;
|
|
|
|
|
break;
|
|
|
|
|
case SET_ENC_RATIO:
|
|
|
|
|
/*
|
2024-05-22 11:38:43 -05:00
|
|
|
|
* The MD90 does not have the concept of encoder ratio, ignore this
|
2003-05-27 13:39:41 +00:00
|
|
|
|
* command
|
|
|
|
|
*/
|
2004-02-20 00:12:28 +00:00
|
|
|
|
send=false;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
trans->state = IDLE_STATE;
|
|
|
|
|
break;
|
|
|
|
|
case GET_INFO:
|
|
|
|
|
/* These commands are not actually done by sending a message, but
|
|
|
|
|
rather they will indirectly cause the driver to read the status
|
|
|
|
|
of all motors */
|
|
|
|
|
break;
|
|
|
|
|
case STOP_AXIS:
|
|
|
|
|
sprintf(motor_call->message, "#%02dQ", axis);
|
|
|
|
|
break;
|
|
|
|
|
case JOG:
|
2024-05-22 11:38:43 -05:00
|
|
|
|
/* MD-90 does not have jog command. Move 1 million steps */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
ival = (int) (fabs(115200./dval) + 0.5);
|
|
|
|
|
if (ival < 2) ival=2;
|
|
|
|
|
if (ival > 65535) ival = 65535;
|
|
|
|
|
sprintf(motor_call->message, "#%02dC=%ld", axis, ival);
|
|
|
|
|
rtnval = motor_end_trans_com(mr, drvtabptr);
|
2024-05-22 11:38:43 -05:00
|
|
|
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MD90_cards);
|
|
|
|
|
motor_call->type = MD90_table[command];
|
2003-05-27 13:39:41 +00:00
|
|
|
|
if (dval > 0.) {
|
2024-05-22 11:38:43 -05:00
|
|
|
|
/* This is a positive move in MD90 coordinates */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
sprintf(motor_call->message, "#%02dM+1000000", axis);
|
|
|
|
|
} else {
|
2024-05-22 11:38:43 -05:00
|
|
|
|
/* This is a negative move in MD90 coordinates */
|
2003-05-27 13:39:41 +00:00
|
|
|
|
sprintf(motor_call->message, "#%02dM-1000000", axis);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SET_PGAIN:
|
|
|
|
|
case SET_IGAIN:
|
|
|
|
|
case SET_DGAIN:
|
2004-02-20 00:12:28 +00:00
|
|
|
|
send=false;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
trans->state = IDLE_STATE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ENABLE_TORQUE:
|
|
|
|
|
sprintf(motor_call->message, "#%02dW=1", axis);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DISABL_TORQUE:
|
|
|
|
|
sprintf(motor_call->message, "#%02dW=0", axis);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SET_HIGH_LIMIT:
|
|
|
|
|
case SET_LOW_LIMIT:
|
2004-02-20 00:12:28 +00:00
|
|
|
|
send=false;
|
2003-05-27 13:39:41 +00:00
|
|
|
|
trans->state = IDLE_STATE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
rtnval = ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-20 00:12:28 +00:00
|
|
|
|
if(send == false)
|
|
|
|
|
return(rtnval);
|
|
|
|
|
else {
|
|
|
|
|
rtnval = motor_end_trans_com(mr, drvtabptr);
|
2024-05-22 11:38:43 -05:00
|
|
|
|
Debug(5, "MD90_send_msg: motor_end_trans_com status=%d, exit\n", rtnval);
|
2004-02-20 00:12:28 +00:00
|
|
|
|
return (rtnval);
|
|
|
|
|
}
|
2003-05-27 13:39:41 +00:00
|
|
|
|
}
|