From a9fc20abee2a4a46ea8928c33ffd76560dfa4f5d Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 26 Jul 2012 15:48:38 +1000 Subject: [PATCH] make poll rates configurable by adding motorPollSlow, motorPollFast and airPollTimer parameters r3682 | dcl | 2012-07-26 15:48:38 +1000 (Thu, 26 Jul 2012) | 1 line --- site_ansto/motor_dmc2280.c | 77 ++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/site_ansto/motor_dmc2280.c b/site_ansto/motor_dmc2280.c index 9b366e7a..96303a0b 100644 --- a/site_ansto/motor_dmc2280.c +++ b/site_ansto/motor_dmc2280.c @@ -168,6 +168,9 @@ struct __MoDriv { double cntsPerX; /**< absolute encoder counts per physical unit */ int motOnDelay; /**< msec to wait after switching motor on */ int motOffDelay; /**< msec to wait before switching motor off */ + int motorPollFast; /**< msec between polls when busy */ + int motorPollSlow; /**< msec between polls when idle */ + int airPollTimer; /**< msec between polls when waiting for airpads */ int currFlags; int currSteps; int currCounts; @@ -231,7 +234,7 @@ struct __MoDriv { int DMC2280MotionControl = 1; /* defaults to enabled */ static bool trace_switches = false; -#define AIR_POLL_TIMER 1000 +#define AIR_POLL_TIMER 250 #define MOTOR_POLL_FAST 100 #define MOTOR_POLL_SLOW 500 #define DEFAULT_DELAY_MOTOR_ON 200 /* msec to wait after switching motor on */ @@ -1801,7 +1804,7 @@ static void DMCState_Unknown(pDMC2280Driv self, pEvtEvent event) { change_state(self, DMCState_Idle); return; } - DMC_SetTimer(self, MOTOR_POLL_SLOW); + DMC_SetTimer(self, self->motorPollSlow); return; case eMessageEvent: do { @@ -1898,9 +1901,9 @@ static void DMCState_Idle(pDMC2280Driv self, pEvtEvent event) { report_motion(self); } if (trace_switches || self->debug) - DMC_SetTimer(self, MOTOR_POLL_FAST); + DMC_SetTimer(self, self->motorPollFast); else - DMC_SetTimer(self, MOTOR_POLL_SLOW); + DMC_SetTimer(self, self->motorPollSlow); self->subState = 0; return; } @@ -1929,7 +1932,7 @@ static void DMCState_Idle(pDMC2280Driv self, pEvtEvent event) { strncpy(self->lastCmd, event->event.msg.cmd->out_buf, CMDLEN); self->errorCode = MOTCMDTMO; self->driver_status = HWFault; - DMC_SetTimer(self, MOTOR_POLL_SLOW); + DMC_SetTimer(self, self->motorPollSlow); self->subState = 0; return; } @@ -2013,7 +2016,7 @@ static void DMCState_MotorStart(pDMC2280Driv self, pEvtEvent event) { return; } else { - DMC_SetTimer(self, AIR_POLL_TIMER); + DMC_SetTimer(self, self->airPollTimer); self->subState = 0; return; } @@ -2033,7 +2036,7 @@ static void DMCState_MotorStart(pDMC2280Driv self, pEvtEvent event) { return; } /* TODO handle airpad timeout */ - DMC_SetTimer(self, AIR_POLL_TIMER); + DMC_SetTimer(self, self->airPollTimer); self->subState = 0; return; } @@ -2257,7 +2260,7 @@ static void DMCState_Moving(pDMC2280Driv self, pEvtEvent event) { return; } self->subState = 2; - DMC_SetTimer(self, MOTOR_POLL_FAST); + DMC_SetTimer(self, self->motorPollFast); return; } else if (self->subState == 3) { /* PA */ @@ -2364,7 +2367,7 @@ static void DMCState_Moving(pDMC2280Driv self, pEvtEvent event) { } } self->subState = 2; - DMC_SetTimer(self, MOTOR_POLL_FAST); + DMC_SetTimer(self, self->motorPollFast); return; } /* Motor has stopped */ @@ -2566,7 +2569,7 @@ static void DMCState_MotorHalt(pDMC2280Driv self, pEvtEvent event) { if (iRet == 0) break; if (self->moving) { - DMC_SetTimer(self, MOTOR_POLL_FAST); + DMC_SetTimer(self, self->motorPollFast); return; } if (self->faultPending) { @@ -2721,7 +2724,7 @@ static void DMCState_MotorStop(pDMC2280Driv self, pEvtEvent event) { } /* TODO handle airpad timeout */ } - DMC_SetTimer(self, AIR_POLL_TIMER); + DMC_SetTimer(self, self->airPollTimer); } while (0); return; case eCommandEvent: @@ -3158,6 +3161,18 @@ static int DMC2280GetPar(void *pData, char *name, *fValue = self->bias_bits; return 1; } + if(strcasecmp(name,"motorPollFast") == 0) { + *fValue = self->motorPollFast; + return 1; + } + if(strcasecmp(name,"motorPollSlow") == 0) { + *fValue = self->motorPollSlow; + return 1; + } + if(strcasecmp(name,"airPollTimer") == 0) { + *fValue = self->airPollTimer; + return 1; + } if (self->posit_count > 0) { if (strncasecmp(name, "posit_", 6) == 0 && isdigit(name[6])) { int index; @@ -3518,6 +3533,27 @@ static int DMC2280SetPar(void *pData, SConnection *pCon, self->bias_bits = newValue; return 1; } + if (self->abs_encoder && strcasecmp("motorPollFast", name) == 0) { + /* Debug Managers only */ + if (!(self->debug && SCMatchRights(pCon, usMugger))) + return 0; + self->motorPollFast = newValue; + return 1; + } + if (self->abs_encoder && strcasecmp("motorPollSlow", name) == 0) { + /* Debug Managers only */ + if (!(self->debug && SCMatchRights(pCon, usMugger))) + return 0; + self->motorPollSlow = newValue; + return 1; + } + if (self->abs_encoder && strcasecmp("airPollTimer", name) == 0) { + /* Debug Managers only */ + if (!(self->debug && SCMatchRights(pCon, usMugger))) + return 0; + self->airPollTimer = newValue; + return 1; + } /* XXX Maybe move this to a configuration parameter.*/ /* Set home, managers only. Users should set softposition */ if(strcasecmp(name, HOME) == 0) { @@ -3612,6 +3648,12 @@ static void DMC2280List(void *pData, char *name, SConnection *pCon){ SCWrite(pCon, buffer, eStatus); snprintf(buffer, BUFFLEN, "%s.motOffDelay = %d\n", name, self->motOffDelay); SCWrite(pCon, buffer, eStatus); + snprintf(buffer, BUFFLEN, "%s.motorPollFast = %d\n", name, self->motorPollFast); + SCWrite(pCon, buffer, eStatus); + snprintf(buffer, BUFFLEN, "%s.motorPollSlow = %d\n", name, self->motorPollSlow); + SCWrite(pCon, buffer, eStatus); + snprintf(buffer, BUFFLEN, "%s.airPollTimer = %d\n", name, self->airPollTimer); + SCWrite(pCon, buffer, eStatus); snprintf(buffer, BUFFLEN, "%s.Debug = %d\n", name, self->debug); SCWrite(pCon, buffer, eStatus); snprintf(buffer, BUFFLEN, "%s.Settle = %d\n", name, self->settle); @@ -3932,6 +3974,19 @@ MotorDriver *CreateDMC2280(SConnection *pCon, char *motor, char *params) { else sscanf(pPtr,"%d",&(pNew->motOffDelay)); + if ((pPtr=getParam(pCon, interp, params,"motorPollFast",_OPTIONAL)) == NULL) + pNew->motorPollFast=MOTOR_POLL_FAST; + else + sscanf(pPtr,"%d",&(pNew->motOffDelay)); + if ((pPtr=getParam(pCon, interp, params,"motorPollSlow",_OPTIONAL)) == NULL) + pNew->motorPollSlow=MOTOR_POLL_SLOW; + else + sscanf(pPtr,"%d",&(pNew->motOffDelay)); + if ((pPtr=getParam(pCon, interp, params,"airPollTimer",_OPTIONAL)) == NULL) + pNew->airPollTimer=AIR_POLL_TIMER; + else + sscanf(pPtr,"%d",&(pNew->motOffDelay)); + /* SETTLE: this motor need time to settle */ if ((pPtr=getParam(pCon, interp, params,"settle",_OPTIONAL)) == NULL) pNew->settle=0;