mirror of
https://github.com/Binary-Coalescence/motorDSM.git
synced 2025-08-04 21:55:40 -05:00
Moved to C++ for R3.14.x.
This commit is contained in:
62
acsApp/src/AcsRegister.cc
Normal file
62
acsApp/src/AcsRegister.cc
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
FILENAME... AcsRegister.cc
|
||||||
|
USAGE... Register ACS motor device driver shell commands.
|
||||||
|
|
||||||
|
Version: $Revision: 1.1 $
|
||||||
|
Modified By: $Author: sluiter $
|
||||||
|
Last Modified: $Date: 2003-05-27 13:39:40 $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
COPYRIGHT NOTIFICATION
|
||||||
|
*****************************************************************
|
||||||
|
|
||||||
|
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
|
||||||
|
|
||||||
|
This software was developed under a United States Government license
|
||||||
|
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||||
|
of this distribution.
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#include <iocsh.h>
|
||||||
|
#include "AcsRegister.h"
|
||||||
|
#include "epicsExport.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
|
||||||
|
// ACS Setup arguments
|
||||||
|
static const iocshArg setupArg0 = {"Max. controller count", iocshArgInt};
|
||||||
|
static const iocshArg setupArg1 = {"N/A", iocshArgInt};
|
||||||
|
static const iocshArg setupArg2 = {"Polling rate", iocshArgInt};
|
||||||
|
// ACS Config arguments
|
||||||
|
static const iocshArg configArg0 = {"Card being configured", iocshArgInt};
|
||||||
|
static const iocshArg configArg1 = {"MPF server location", iocshArgInt};
|
||||||
|
static const iocshArg configArg2 = {"MPF server task name", iocshArgString};
|
||||||
|
|
||||||
|
static const iocshArg * const MCB4BSetupArgs[3] = {&setupArg0, &setupArg1,
|
||||||
|
&setupArg2};
|
||||||
|
static const iocshArg * const MCB4BConfigArgs[3] = {&configArg0, &configArg1,
|
||||||
|
&configArg2};
|
||||||
|
|
||||||
|
static const iocshFuncDef setupMCB4B = {"MCB4BSetup", 3, MCB4BSetupArgs};
|
||||||
|
static const iocshFuncDef configMCB4B = {"MCB4BConfig", 3, MCB4BConfigArgs};
|
||||||
|
|
||||||
|
static void setupMCB4BCallFunc(const iocshArgBuf *args)
|
||||||
|
{
|
||||||
|
MCB4BSetup(args[0].ival, args[1].ival, args[2].ival);
|
||||||
|
}
|
||||||
|
static void configMCB4BCallFunc(const iocshArgBuf *args)
|
||||||
|
{
|
||||||
|
MCB4BConfig(args[0].ival, args[1].ival, args[2].sval);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AcsRegister(void)
|
||||||
|
{
|
||||||
|
iocshRegister(&setupMCB4B, setupMCB4BCallFunc);
|
||||||
|
iocshRegister(&configMCB4B, configMCB4BCallFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
epicsExportRegistrar(AcsRegister);
|
||||||
|
|
||||||
|
} // extern "C"
|
45
acsApp/src/AcsRegister.h
Normal file
45
acsApp/src/AcsRegister.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
FILENAME... AcsRegister.h
|
||||||
|
USAGE... This file contains function prototypes for ACS IOC shell commands.
|
||||||
|
|
||||||
|
Version: $Revision: 1.1 $
|
||||||
|
Modified By: $Author: sluiter $
|
||||||
|
Last Modified: $Date: 2003-05-27 13:39:40 $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Original Author: Ron Sluiter
|
||||||
|
* Date: 05/19/03
|
||||||
|
*
|
||||||
|
* Experimental Physics and Industrial Control System (EPICS)
|
||||||
|
*
|
||||||
|
* Copyright 1991, the Regents of the University of California,
|
||||||
|
* and the University of Chicago Board of Governors.
|
||||||
|
*
|
||||||
|
* This software was produced under U.S. Government contracts:
|
||||||
|
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
|
||||||
|
* and (W-31-109-ENG-38) at Argonne National Laboratory.
|
||||||
|
*
|
||||||
|
* Initial development by:
|
||||||
|
* The Controls and Automation Group (AT-8)
|
||||||
|
* Ground Test Accelerator
|
||||||
|
* Accelerator Technology Division
|
||||||
|
* Los Alamos National Laboratory
|
||||||
|
*
|
||||||
|
* Co-developed with
|
||||||
|
* The Controls and Computing Group
|
||||||
|
* Accelerator Systems Division
|
||||||
|
* Advanced Photon Source
|
||||||
|
* Argonne National Laboratory
|
||||||
|
*
|
||||||
|
* Modification Log:
|
||||||
|
* -----------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "motor.h"
|
||||||
|
#include "motordrvCom.h"
|
||||||
|
|
||||||
|
/* Function prototypes. */
|
||||||
|
extern RTN_STATUS MCB4BSetup(int, int, int);
|
||||||
|
extern RTN_STATUS MCB4BConfig(int, int, const char *);
|
||||||
|
|
329
acsApp/src/devMCB4B.cc
Normal file
329
acsApp/src/devMCB4B.cc
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
/* File: devMCB4B.cc */
|
||||||
|
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define VERSION 1.00
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "motorRecord.h"
|
||||||
|
#include "motor.h"
|
||||||
|
#include "motordevCom.h"
|
||||||
|
#include "drvMCB4B.h"
|
||||||
|
#include "epicsExport.h"
|
||||||
|
|
||||||
|
#define STATIC static
|
||||||
|
|
||||||
|
extern struct driver_table MCB4B_access;
|
||||||
|
|
||||||
|
#define NINT(f) (long)((f)>0 ? (f)+0.5 : (f)-0.5)
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#ifdef DEBUG
|
||||||
|
volatile int devMCB4BDebug = 0;
|
||||||
|
#define Debug(l, f, args...) { if(l<=devMCB4BDebug) printf(f,## args); }
|
||||||
|
#else
|
||||||
|
#define Debug(l, f, args...)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define Debug()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
#ifdef NODEBUG
|
||||||
|
#define Debug(L,FMT,V) ;
|
||||||
|
#else
|
||||||
|
#define Debug(L,FMT,V...) { if(L <= devMCB4BDebug) \
|
||||||
|
{ errlogPrintf("%s(%d):",__FILE__,__LINE__); \
|
||||||
|
errlogPrintf(FMT,##V); } }
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Debugging levels:
|
||||||
|
* devMCB4BDebug >= 3 Print new part of command and command string so far
|
||||||
|
* at the end of MCB4B_build_trans
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------Create the dsets for devMCB4B----------------- */
|
||||||
|
STATIC struct driver_table *drvtabptr;
|
||||||
|
STATIC long MCB4B_init(void *);
|
||||||
|
STATIC long MCB4B_init_record(void *);
|
||||||
|
STATIC long MCB4B_start_trans(struct motorRecord *);
|
||||||
|
STATIC RTN_STATUS MCB4B_build_trans(motor_cmnd, double *, struct motorRecord *);
|
||||||
|
STATIC RTN_STATUS MCB4B_end_trans(struct motorRecord *);
|
||||||
|
|
||||||
|
struct motor_dset devMCB4B =
|
||||||
|
{
|
||||||
|
{8, NULL, (DEVSUPFUN) MCB4B_init, (DEVSUPFUN) MCB4B_init_record, NULL},
|
||||||
|
motor_update_values,
|
||||||
|
MCB4B_start_trans,
|
||||||
|
MCB4B_build_trans,
|
||||||
|
MCB4B_end_trans
|
||||||
|
};
|
||||||
|
|
||||||
|
epicsExportAddress(dset,devMCB4B);
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------- program data --------------------- */
|
||||||
|
/* This table is used to define the command types */
|
||||||
|
|
||||||
|
static msg_types MCB4B_table[] = {
|
||||||
|
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 */
|
||||||
|
IMMEDIATE /* SET_LOW_LIMIT */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct board_stat **MCB4B_cards;
|
||||||
|
|
||||||
|
/* --------------------------- program data --------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
/* initialize device support for MCB4B stepper motor */
|
||||||
|
STATIC long MCB4B_init(void *arg)
|
||||||
|
{
|
||||||
|
long rtnval;
|
||||||
|
int after = (int) arg;
|
||||||
|
|
||||||
|
Debug(5, "MCB4B_init: entry\n");
|
||||||
|
if (after == 0)
|
||||||
|
{
|
||||||
|
drvtabptr = &MCB4B_access;
|
||||||
|
(drvtabptr->init)();
|
||||||
|
}
|
||||||
|
|
||||||
|
rtnval = motor_init_com(after, *drvtabptr->cardcnt_ptr, drvtabptr, &MCB4B_cards);
|
||||||
|
Debug(5, "MCB4B_init: exit\n");
|
||||||
|
return(rtnval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* initialize a record instance */
|
||||||
|
STATIC long MCB4B_init_record(void *arg)
|
||||||
|
{
|
||||||
|
struct motorRecord *mr = (struct motorRecord *) arg;
|
||||||
|
long rtnval;
|
||||||
|
|
||||||
|
Debug(5, "MCB4B_init_record: entry\n");
|
||||||
|
rtnval = motor_init_record_com(mr, *drvtabptr->cardcnt_ptr,
|
||||||
|
drvtabptr, MCB4B_cards);
|
||||||
|
return(rtnval);
|
||||||
|
Debug(5, "MCB4B_init_record: exit\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* start building a transaction */
|
||||||
|
STATIC long MCB4B_start_trans(struct motorRecord *mr)
|
||||||
|
{
|
||||||
|
return(OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* end building a transaction */
|
||||||
|
STATIC RTN_STATUS MCB4B_end_trans(struct motorRecord *mr)
|
||||||
|
{
|
||||||
|
return(OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add a part to the transaction */
|
||||||
|
STATIC RTN_STATUS MCB4B_build_trans(motor_cmnd command, double *parms, struct motorRecord *mr)
|
||||||
|
{
|
||||||
|
struct motor_trans *trans = (struct motor_trans *) mr->dpvt;
|
||||||
|
struct mess_node *motor_call;
|
||||||
|
struct controller *brdptr;
|
||||||
|
struct MCB4Bcontroller *cntrl;
|
||||||
|
char buff[30];
|
||||||
|
int axis, card;
|
||||||
|
RTN_STATUS rtnval;
|
||||||
|
double dval;
|
||||||
|
long ival;
|
||||||
|
|
||||||
|
rtnval = OK;
|
||||||
|
buff[0] = '\0';
|
||||||
|
dval = parms[0];
|
||||||
|
ival = NINT(parms[0]);
|
||||||
|
|
||||||
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MCB4B_cards);
|
||||||
|
Debug(5, "MCB4B_build_trans: entry, motor_start_trans_com=%ld\n", rtnval);
|
||||||
|
|
||||||
|
motor_call = &(trans->motor_call);
|
||||||
|
motor_call->type = MCB4B_table[command];
|
||||||
|
card = motor_call->card;
|
||||||
|
axis = motor_call->signal;
|
||||||
|
brdptr = (*trans->tabptr->card_array)[card];
|
||||||
|
Debug(5, "MCB4B_build_trans: axis=%d, command=%d\n", axis, command);
|
||||||
|
if (brdptr == NULL)
|
||||||
|
return(rtnval = ERROR);
|
||||||
|
|
||||||
|
cntrl = (struct MCB4Bcontroller *) brdptr->DevicePrivate;
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MCB4B_cards);
|
||||||
|
motor_call->type = MCB4B_table[command];
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MCB4B_cards);
|
||||||
|
motor_call->type = MCB4B_table[command];
|
||||||
|
}
|
||||||
|
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:
|
||||||
|
trans->state = IDLE_STATE;
|
||||||
|
break; /* MCB4B does not use base velocity */
|
||||||
|
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 */
|
||||||
|
/* MCB is programmed with Ramp Index (R) where: */
|
||||||
|
/* 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:
|
||||||
|
/*
|
||||||
|
* The MCB4B starts moving immediately on move commands, GO command
|
||||||
|
* does nothing
|
||||||
|
*/
|
||||||
|
trans->state = IDLE_STATE;
|
||||||
|
break;
|
||||||
|
case SET_ENC_RATIO:
|
||||||
|
/*
|
||||||
|
* The MCB4B does not have the concept of encoder ratio, ignore this
|
||||||
|
* command
|
||||||
|
*/
|
||||||
|
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:
|
||||||
|
/* MCB-4B does not have jog command. Move 1 million steps */
|
||||||
|
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);
|
||||||
|
rtnval = (RTN_STATUS) motor_start_trans_com(mr, MCB4B_cards);
|
||||||
|
motor_call->type = MCB4B_table[command];
|
||||||
|
if (dval > 0.) {
|
||||||
|
/* This is a positive move in MCB4B coordinates */
|
||||||
|
sprintf(motor_call->message, "#%02dM+1000000", axis);
|
||||||
|
} else {
|
||||||
|
/* This is a negative move in MCB4B coordinates */
|
||||||
|
sprintf(motor_call->message, "#%02dM-1000000", axis);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SET_PGAIN:
|
||||||
|
trans->state = IDLE_STATE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SET_IGAIN:
|
||||||
|
trans->state = IDLE_STATE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SET_DGAIN:
|
||||||
|
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:
|
||||||
|
trans->state = IDLE_STATE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rtnval = ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtnval = motor_end_trans_com(mr, drvtabptr);
|
||||||
|
Debug(5, "MCB4B_send_msg: motor_end_trans_com status=%ld, exit\n", rtnval);
|
||||||
|
return (rtnval);
|
||||||
|
}
|
535
acsApp/src/drvMCB4B.cc
Normal file
535
acsApp/src/drvMCB4B.cc
Normal file
@@ -0,0 +1,535 @@
|
|||||||
|
/* File: drvMCB4B.cc */
|
||||||
|
|
||||||
|
/* Device Driver Support routines for motor */
|
||||||
|
/*
|
||||||
|
* Original Author: Mark Rivers
|
||||||
|
* Date: 2/24/2002
|
||||||
|
*
|
||||||
|
* Modification Log:
|
||||||
|
* -----------------
|
||||||
|
* .01 02-24-2002 mlr initialized from drvPM304.c
|
||||||
|
* .02 07-03-2002 rls replaced RA_OVERTRAVEL with RA_PLUS_LS and RA_MINUS_LS
|
||||||
|
* .03 05-23-2003 rls Converted to R3.14.x.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <epicsThread.h>
|
||||||
|
#include <drvSup.h>
|
||||||
|
#include "motor.h"
|
||||||
|
#include "AcsRegister.h"
|
||||||
|
#include "drvMCB4B.h"
|
||||||
|
#include "serialIO.h"
|
||||||
|
#include "epicsExport.h"
|
||||||
|
|
||||||
|
#define STATIC static
|
||||||
|
|
||||||
|
#define WAIT 1
|
||||||
|
|
||||||
|
#define SERIAL_TIMEOUT 2000 /* Command timeout in msec */
|
||||||
|
|
||||||
|
#define BUFF_SIZE 100 /* Maximum length of string to/from MCB4B */
|
||||||
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#ifdef DEBUG
|
||||||
|
volatile int drvMCB4BDebug = 0;
|
||||||
|
#define Debug(l, f, args...) { if(l<=drvMCB4BDebug) printf(f,## args); }
|
||||||
|
#else
|
||||||
|
#define Debug(l, f, args...)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define Debug()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
#ifdef NODEBUG
|
||||||
|
#define Debug(L,FMT,V) ;
|
||||||
|
#else
|
||||||
|
#define Debug(L,FMT,V...) { if(L <= drvMCB4BDebug) \
|
||||||
|
{ errlogPrintf("%s(%d):",__FILE__,__LINE__); \
|
||||||
|
errlogPrintf(FMT,##V); } }
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Debugging notes:
|
||||||
|
* drvMCB4BDebug == 0 No debugging information is printed
|
||||||
|
* drvMCB4BDebug >= 1 Warning information is printed
|
||||||
|
* drvMCB4BDebug >= 2 Time-stamped messages are printed for each string
|
||||||
|
* sent to and received from the controller
|
||||||
|
* drvMCB4BDebug >= 3 Additional debugging messages
|
||||||
|
*/
|
||||||
|
|
||||||
|
int MCB4B_num_cards = 0;
|
||||||
|
volatile int drvMCB4BDebug = 0;
|
||||||
|
|
||||||
|
/* Local data required for every driver; see "motordrvComCode.h" */
|
||||||
|
#include "motordrvComCode.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------functions-----------------*/
|
||||||
|
STATIC int recv_mess(int, char *, int);
|
||||||
|
STATIC RTN_STATUS send_mess(int card, const char *com, char c);
|
||||||
|
STATIC void start_status(int card);
|
||||||
|
STATIC int set_status(int card, int signal);
|
||||||
|
static long report(int level);
|
||||||
|
static long init();
|
||||||
|
STATIC int motor_init();
|
||||||
|
STATIC void query_done(int, int, struct mess_node *);
|
||||||
|
|
||||||
|
/*----------------functions-----------------*/
|
||||||
|
|
||||||
|
struct driver_table MCB4B_access =
|
||||||
|
{
|
||||||
|
motor_init,
|
||||||
|
motor_send,
|
||||||
|
motor_free,
|
||||||
|
motor_card_info,
|
||||||
|
motor_axis_info,
|
||||||
|
&mess_queue,
|
||||||
|
&queue_lock,
|
||||||
|
&free_list,
|
||||||
|
&freelist_lock,
|
||||||
|
&motor_sem,
|
||||||
|
&motor_state,
|
||||||
|
&total_cards,
|
||||||
|
&any_motor_in_motion,
|
||||||
|
send_mess,
|
||||||
|
recv_mess,
|
||||||
|
set_status,
|
||||||
|
query_done,
|
||||||
|
start_status,
|
||||||
|
&initialized
|
||||||
|
};
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
long number;
|
||||||
|
#ifdef __cplusplus
|
||||||
|
long (*report) (int);
|
||||||
|
long (*init) (void);
|
||||||
|
#else
|
||||||
|
DRVSUPFUN report;
|
||||||
|
DRVSUPFUN init;
|
||||||
|
#endif
|
||||||
|
} drvMCB4B = {2, report, init};
|
||||||
|
|
||||||
|
epicsExportAddress(drvet, drvMCB4B);
|
||||||
|
|
||||||
|
STATIC struct thread_args targs = {SCAN_RATE, &MCB4B_access};
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************
|
||||||
|
* Print out driver status report
|
||||||
|
*********************************************************/
|
||||||
|
static long report(int level)
|
||||||
|
{
|
||||||
|
int card;
|
||||||
|
|
||||||
|
if (MCB4B_num_cards <=0)
|
||||||
|
printf(" NO MCB4B controllers found\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (card = 0; card < MCB4B_num_cards; card++)
|
||||||
|
if (motor_state[card])
|
||||||
|
printf(" MCB4B controller %d, id: %s \n",
|
||||||
|
card,
|
||||||
|
motor_state[card]->ident);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static long init()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* We cannot call motor_init() here, because that function can do GPIB I/O,
|
||||||
|
* and hence requires that the drvGPIB have already been initialized.
|
||||||
|
* That cannot be guaranteed, so we need to call motor_init from device
|
||||||
|
* support
|
||||||
|
*/
|
||||||
|
/* Check for setup */
|
||||||
|
if (MCB4B_num_cards <= 0)
|
||||||
|
{
|
||||||
|
Debug(1, "init: *MCB4B driver disabled*\n");
|
||||||
|
Debug(1, "MCB4BSetup() is missing from startup script.\n");
|
||||||
|
return (ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((long) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC void query_done(int card, int axis, struct mess_node *nodeptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************
|
||||||
|
* Read the status and position of all motors on a card
|
||||||
|
* start_status(int card)
|
||||||
|
* if card == -1 then start all cards
|
||||||
|
*********************************************************/
|
||||||
|
STATIC void start_status(int card)
|
||||||
|
{
|
||||||
|
/* The MCB4B cannot query status or positions of all axes with a
|
||||||
|
* single command. This needs to be done on an axis-by-axis basis,
|
||||||
|
* so this function does nothing
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************
|
||||||
|
* Query position and status for an axis
|
||||||
|
* set_status()
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
STATIC int set_status(int card, int signal)
|
||||||
|
{
|
||||||
|
register struct mess_info *motor_info;
|
||||||
|
char command[BUFF_SIZE];
|
||||||
|
char response[BUFF_SIZE];
|
||||||
|
struct mess_node *nodeptr;
|
||||||
|
int rtn_state;
|
||||||
|
long motorData;
|
||||||
|
char buff[BUFF_SIZE];
|
||||||
|
bool ls_active = false;
|
||||||
|
|
||||||
|
motor_info = &(motor_state[card]->motor_info[signal]);
|
||||||
|
nodeptr = motor_info->motor_motion;
|
||||||
|
|
||||||
|
/* Request the moving status of this motor */
|
||||||
|
sprintf(command, "#%02dX", signal);
|
||||||
|
send_mess(card, command, 0);
|
||||||
|
recv_mess(card, response, WAIT);
|
||||||
|
/* The response string is of the form "#01X=1" */
|
||||||
|
|
||||||
|
if (response[5] == '1')
|
||||||
|
motor_info->status &= ~RA_DONE;
|
||||||
|
else {
|
||||||
|
motor_info->status |= RA_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request the limit status of this motor */
|
||||||
|
sprintf(command, "#%02dE", signal);
|
||||||
|
send_mess(card, command, 0);
|
||||||
|
recv_mess(card, response, WAIT);
|
||||||
|
/* The response string is of the form "#01E=1" */
|
||||||
|
motor_info->status &= ~(RA_PLUS_LS | RA_MINUS_LS);
|
||||||
|
if (response[5] == '1') {
|
||||||
|
motor_info->status |= RA_PLUS_LS;
|
||||||
|
motor_info->status |= RA_DIRECTION;
|
||||||
|
ls_active = true;
|
||||||
|
}
|
||||||
|
if (response[6] == '1') {
|
||||||
|
motor_info->status |= RA_MINUS_LS;
|
||||||
|
motor_info->status &= ~RA_DIRECTION;
|
||||||
|
ls_active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* encoder status */
|
||||||
|
motor_info->status &= ~EA_SLIP;
|
||||||
|
motor_info->status &= ~EA_POSITION;
|
||||||
|
motor_info->status &= ~EA_SLIP_STALL;
|
||||||
|
motor_info->status &= ~EA_HOME;
|
||||||
|
|
||||||
|
/* Request the position of this motor */
|
||||||
|
sprintf(command, "#%02dP", signal);
|
||||||
|
send_mess(card, command, 0);
|
||||||
|
recv_mess(card, response, WAIT);
|
||||||
|
/* The response string is of the form "#01P=+1000" */
|
||||||
|
motorData = atoi(&response[5]);
|
||||||
|
|
||||||
|
if (motorData == motor_info->position)
|
||||||
|
motor_info->no_motion_count++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
motor_info->position = motorData;
|
||||||
|
motor_info->encoder_position = motorData;
|
||||||
|
motor_info->no_motion_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse motor velocity? */
|
||||||
|
/* NEEDS WORK */
|
||||||
|
|
||||||
|
motor_info->velocity = 0;
|
||||||
|
|
||||||
|
if (!(motor_info->status & RA_DIRECTION))
|
||||||
|
motor_info->velocity *= -1;
|
||||||
|
|
||||||
|
rtn_state = (!motor_info->no_motion_count || ls_active == true ||
|
||||||
|
(motor_info->status & (RA_DONE | RA_PROBLEM))) ? 1 : 0;
|
||||||
|
|
||||||
|
/* Test for post-move string. */
|
||||||
|
if ((motor_info->status & RA_DONE || ls_active == true) && nodeptr != 0 &&
|
||||||
|
nodeptr->postmsgptr != 0)
|
||||||
|
{
|
||||||
|
strcpy(buff, nodeptr->postmsgptr);
|
||||||
|
strcat(buff, "\r");
|
||||||
|
send_mess(card, buff, NULL);
|
||||||
|
/* The MCB4B always sends back a response, read it and discard */
|
||||||
|
recv_mess(card, buff, WAIT);
|
||||||
|
nodeptr->postmsgptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (rtn_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************/
|
||||||
|
/* send a message to the MCB4B board */
|
||||||
|
/* send_mess() */
|
||||||
|
/*****************************************************/
|
||||||
|
STATIC RTN_STATUS send_mess(int card, const char *com, char c)
|
||||||
|
{
|
||||||
|
char buff[BUFF_SIZE];
|
||||||
|
struct MCB4Bcontroller *cntrl;
|
||||||
|
|
||||||
|
/* Check that card exists */
|
||||||
|
if (!motor_state[card])
|
||||||
|
{
|
||||||
|
errlogPrintf("send_mess - invalid card #%d\n", card);
|
||||||
|
return (ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the string is NULL just return */
|
||||||
|
if (strlen(com) == 0) return(OK);
|
||||||
|
cntrl = (struct MCB4Bcontroller *) motor_state[card]->DevicePrivate;
|
||||||
|
|
||||||
|
strcpy(buff, com);
|
||||||
|
strcat(buff, OUTPUT_TERMINATOR);
|
||||||
|
/*
|
||||||
|
Debug(2, "%.2f : send_mess: sending message to card %d, message=%s\n",
|
||||||
|
tickGet()/60., card, buff);
|
||||||
|
*/
|
||||||
|
serialIOSend(cntrl->serialInfo, buff, strlen(buff), SERIAL_TIMEOUT);
|
||||||
|
|
||||||
|
return (OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************/
|
||||||
|
/* Read a response string from the MCB4B board */
|
||||||
|
/* recv_mess() */
|
||||||
|
/*****************************************************/
|
||||||
|
STATIC int recv_mess(int card, char *com, int flag)
|
||||||
|
{
|
||||||
|
int timeout;
|
||||||
|
int len=0;
|
||||||
|
struct MCB4Bcontroller *cntrl;
|
||||||
|
|
||||||
|
/* Check that card exists */
|
||||||
|
if (!motor_state[card])
|
||||||
|
{
|
||||||
|
errlogPrintf("recv_mess - invalid card #%d\n", card);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cntrl = (struct MCB4Bcontroller *) motor_state[card]->DevicePrivate;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Debug(3, "%.2f : recv_mess entry: card %d, flag=%d\n",
|
||||||
|
tickGet()/60., card, flag);
|
||||||
|
*/
|
||||||
|
if (flag == FLUSH)
|
||||||
|
timeout = 0;
|
||||||
|
else
|
||||||
|
timeout = SERIAL_TIMEOUT;
|
||||||
|
len = serialIORecv(cntrl->serialInfo, com, MAX_MSG_SIZE,
|
||||||
|
(char *) "\r", timeout);
|
||||||
|
|
||||||
|
/* The response from the MCB4B is terminated with CR. Remove */
|
||||||
|
if (len < 1) com[0] = '\0';
|
||||||
|
else com[len-1] = '\0';
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (len > 0) {
|
||||||
|
Debug(2, "%.2f : recv_mess: card %d, message = \"%s\"\n",
|
||||||
|
tickGet()/60., card, com);
|
||||||
|
}
|
||||||
|
if (len == 0) {
|
||||||
|
if (flag != FLUSH) {
|
||||||
|
Debug(1, "%.2f: recv_mess: card %d ERROR: no response\n",
|
||||||
|
tickGet()/60., card);
|
||||||
|
} else {
|
||||||
|
Debug(3, "%.2f: recv_mess: card %d flush returned no characters\n",
|
||||||
|
tickGet()/60., card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************/
|
||||||
|
/* Setup system configuration */
|
||||||
|
/* MCB4BSetup() */
|
||||||
|
/*****************************************************/
|
||||||
|
RTN_STATUS
|
||||||
|
MCB4BSetup(int num_cards, /* maximum number of controllers in system */
|
||||||
|
int num_channels, /* NOT USED */
|
||||||
|
int scan_rate) /* polling rate - 1/60 sec units */
|
||||||
|
{
|
||||||
|
int itera;
|
||||||
|
|
||||||
|
if (num_cards < 1 || num_cards > MCB4B_NUM_CARDS)
|
||||||
|
MCB4B_num_cards = MCB4B_NUM_CARDS;
|
||||||
|
else
|
||||||
|
MCB4B_num_cards = num_cards;
|
||||||
|
|
||||||
|
/* Set motor polling task rate */
|
||||||
|
if (scan_rate >= 1 && scan_rate <= 60)
|
||||||
|
targs.motor_scan_rate = scan_rate;
|
||||||
|
else
|
||||||
|
targs.motor_scan_rate = SCAN_RATE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate space for motor_state structure pointers. Note this must be done
|
||||||
|
* before MCB4BConfig is called, so it cannot be done in motor_init()
|
||||||
|
* This means that we must allocate space for a card without knowing
|
||||||
|
* if it really exists, which is not a serious problem since this is just
|
||||||
|
* an array of pointers.
|
||||||
|
*/
|
||||||
|
motor_state = (struct controller **) malloc(MCB4B_num_cards *
|
||||||
|
sizeof(struct controller *));
|
||||||
|
|
||||||
|
for (itera = 0; itera < MCB4B_num_cards; itera++)
|
||||||
|
motor_state[itera] = (struct controller *) NULL;
|
||||||
|
return (OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************/
|
||||||
|
/* Configure a controller */
|
||||||
|
/* MCB4BConfig() */
|
||||||
|
/*****************************************************/
|
||||||
|
RTN_STATUS
|
||||||
|
MCB4BConfig(int card, /* card being configured */
|
||||||
|
int location, /* card for RS-232 */
|
||||||
|
const char *name) /* server_task for RS-232 */
|
||||||
|
{
|
||||||
|
struct MCB4Bcontroller *cntrl;
|
||||||
|
|
||||||
|
if (card < 0 || card >= MCB4B_num_cards)
|
||||||
|
return (ERROR);
|
||||||
|
|
||||||
|
motor_state[card] = (struct controller *) malloc(sizeof(struct controller));
|
||||||
|
motor_state[card]->DevicePrivate = malloc(sizeof(struct MCB4Bcontroller));
|
||||||
|
cntrl = (struct MCB4Bcontroller *) motor_state[card]->DevicePrivate;
|
||||||
|
cntrl->serial_card = location;
|
||||||
|
strcpy(cntrl->serial_task, name);
|
||||||
|
return (OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************/
|
||||||
|
/* initialize all software and hardware */
|
||||||
|
/* This is called from the initialization routine in */
|
||||||
|
/* device support. */
|
||||||
|
/* motor_init() */
|
||||||
|
/*****************************************************/
|
||||||
|
STATIC int motor_init()
|
||||||
|
{
|
||||||
|
struct controller *brdptr;
|
||||||
|
struct MCB4Bcontroller *cntrl;
|
||||||
|
int card_index, motor_index;
|
||||||
|
char buff[BUFF_SIZE];
|
||||||
|
int total_axis = 0;
|
||||||
|
int status = 0;
|
||||||
|
bool errind;
|
||||||
|
|
||||||
|
initialized = true; /* Indicate that driver is initialized. */
|
||||||
|
|
||||||
|
/* Check for setup */
|
||||||
|
if (MCB4B_num_cards <= 0)
|
||||||
|
{
|
||||||
|
Debug(1, "motor_init: *MCB4B driver disabled*\n");
|
||||||
|
Debug(1, "MCB4BSetup() is missing from startup script.\n");
|
||||||
|
return (ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (card_index = 0; card_index < MCB4B_num_cards; card_index++)
|
||||||
|
{
|
||||||
|
if (!motor_state[card_index])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
brdptr = motor_state[card_index];
|
||||||
|
total_cards = card_index + 1;
|
||||||
|
cntrl = (struct MCB4Bcontroller *) brdptr->DevicePrivate;
|
||||||
|
|
||||||
|
/* Initialize communications channel */
|
||||||
|
errind = false;
|
||||||
|
|
||||||
|
cntrl->serialInfo = serialIOInit(cntrl->serial_card,
|
||||||
|
cntrl->serial_task);
|
||||||
|
if (cntrl->serialInfo == NULL)
|
||||||
|
errind = true;
|
||||||
|
|
||||||
|
if (errind == false)
|
||||||
|
{
|
||||||
|
int retry = 0;
|
||||||
|
|
||||||
|
/* Send a message to the board, see if it exists */
|
||||||
|
/* flush any junk at input port - should not be any data available */
|
||||||
|
do {
|
||||||
|
recv_mess(card_index, buff, FLUSH);
|
||||||
|
} while (strlen(buff) != 0);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
send_mess(card_index, "#00X", 0);
|
||||||
|
status = recv_mess(card_index, buff, WAIT);
|
||||||
|
retry++;
|
||||||
|
/* Return value is length of response string */
|
||||||
|
} while(status == 0 && retry < 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (errind == false && status > 0)
|
||||||
|
{
|
||||||
|
brdptr->localaddr = (char *) NULL;
|
||||||
|
brdptr->motor_in_motion = 0;
|
||||||
|
brdptr->cmnd_response = true;
|
||||||
|
|
||||||
|
/* Assume that this controller has 4 axes. */
|
||||||
|
total_axis = 4;
|
||||||
|
brdptr->total_axis = total_axis;
|
||||||
|
start_status(card_index);
|
||||||
|
for (motor_index = 0; motor_index < total_axis; motor_index++)
|
||||||
|
{
|
||||||
|
struct mess_info *motor_info = &brdptr->motor_info[motor_index];
|
||||||
|
brdptr->motor_info[motor_index].motor_motion = NULL;
|
||||||
|
/* Don't turn on motor power, too dangerous */
|
||||||
|
sprintf(buff,"#%02dW=1", motor_index);
|
||||||
|
/* send_mess(card_index, buff, 0); */
|
||||||
|
/* Stop motor */
|
||||||
|
sprintf(buff,"#%02dQ", motor_index);
|
||||||
|
send_mess(card_index, buff, 0);
|
||||||
|
recv_mess(card_index, buff, WAIT); /* Throw away response */
|
||||||
|
strcpy(brdptr->ident, "MCB-4B");
|
||||||
|
motor_info->status = 0;
|
||||||
|
motor_info->no_motion_count = 0;
|
||||||
|
motor_info->encoder_position = 0;
|
||||||
|
motor_info->position = 0;
|
||||||
|
set_status(card_index, motor_index); /* Read status of each motor */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
motor_state[card_index] = (struct controller *) NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
any_motor_in_motion = 0;
|
||||||
|
|
||||||
|
mess_queue.head = (struct mess_node *) NULL;
|
||||||
|
mess_queue.tail = (struct mess_node *) NULL;
|
||||||
|
|
||||||
|
free_list.head = (struct mess_node *) NULL;
|
||||||
|
free_list.tail = (struct mess_node *) NULL;
|
||||||
|
|
||||||
|
Debug(3, "motor_init: spawning motor task\n");
|
||||||
|
|
||||||
|
epicsThreadCreate((char *) "tMCB4B", 64, 5000, (EPICSTHREADFUNC) motor_task, (void *) &targs);
|
||||||
|
|
||||||
|
return(OK);
|
||||||
|
}
|
Reference in New Issue
Block a user