Don't change anything on startup, defer settings until moving and then do each time

We don't want to change anything on the controller when we start SICS so we don't interfere with whatever else is talking to it. So don't command it during init.

We also want to send Speed, Accel and Decel on each move so we defer those until then.
r3622 | dcl | 2012-06-28 15:39:47 +1000 (Thu, 28 Jun 2012) | 5 lines
This commit is contained in:
Douglas Clowes
2012-06-28 15:39:47 +10:00
parent 2c4f45b573
commit 66caf6916b

View File

@@ -36,6 +36,8 @@
#define TEXTPARLEN 1024
#define CMDLEN 1024
#define STATE_TRACE (200)
#define DECADIC_CREEP (10)
#define SPEED_ON_MOVE 1
/** \brief Used to ensure that the getDMCSetting function is called
* with valid values.
@@ -471,7 +473,7 @@ static int motSpeed(pDMC2280Driv self, double axisSpeed) {
}
/** \brief Convert axis acceleration in physical units to
* motor speed in steps/sec^2
* motor acceleration in steps/sec^2
*
* \param self (r) provides access to the motor's data structure
* \param acceleration in physical units, eg mm/sec^2 degrees/sec^2
@@ -602,14 +604,14 @@ static int motCreep(pDMC2280Driv self, double target) {
if (self->creep_val > 0) /* moving down handle as positive */
offset = -offset;
if (offset > fabs(self->stepsPerX * self->creep_precision)) {
#if 1
#ifdef DECADIC_CREEP
/* if half offset is more than creep_offset warp to creep_offset */
if (offset > (int) (2.0 * fabs(self->stepsPerX * self->creep_offset)))
offset = offset - fabs(self->stepsPerX * self->creep_offset);
else {
/* if closer than one count, single step else go half way */
/* if closer than one count, "single step" else go half way */
if (offset <= fabs(self->stepsPerX / self->cntsPerX)) {
offset = offset / 10;
offset = offset / DECADIC_CREEP;
if (offset < 1)
offset = 1;
}
@@ -1308,6 +1310,39 @@ static int cmdOff(pDMC2280Driv self) {
return DMC_SendReq(self, cmd);
}
static int cmdSpeed(pDMC2280Driv self) {
char cmd[CMDLEN];
int value;
value = motSpeed(self, self->speed);
snprintf(cmd, CMDLEN, "SP%c=%d", self->axisLabel, value);
if (FAILURE == DMC_Send(self, cmd)) {
return 0; /* FIXME should signal a HWFault */
}
return 1;
}
static int cmdAccel(pDMC2280Driv self) {
char cmd[CMDLEN];
int value;
value = motAccel(self, self->accel);
snprintf(cmd, CMDLEN, "AC%c=%d", self->axisLabel, value);
if (FAILURE == DMC_Send(self, cmd)) {
return 0; /* FIXME should signal a HWFault */
}
return 1;
}
static int cmdDecel(pDMC2280Driv self) {
char cmd[CMDLEN];
int value;
value = motDecel(self, self->decel);
snprintf(cmd, CMDLEN, "DC%c=%d", self->axisLabel, value);
if (FAILURE == DMC_Send(self, cmd)) {
return 0; /* FIXME should signal a HWFault */
}
return 1;
}
static int rspStatus(pDMC2280Driv self, const char* text) {
int iRet, iFlags;
int iSteps, iCounts;
@@ -1715,6 +1750,9 @@ static void DMCState_Unknown(pDMC2280Driv self, pEvtEvent event) {
/* FIXME: FIXME_DOUG */
return;
}
#ifdef SPEED_ON_MOVE
/* Defer Speed, Accel and Decel to move command */
#else
/* Set speed */
value = motSpeed(self, self->speed);
snprintf(cmd, CMDLEN, "SP%c=%d", self->axisLabel, value);
@@ -1733,6 +1771,7 @@ static void DMCState_Unknown(pDMC2280Driv self, pEvtEvent event) {
if (FAILURE == DMC_Send(self, cmd)) {
break;
}
#endif
cmdVars(self);
self->subState = 1;
return;
@@ -1800,11 +1839,13 @@ static void DMCState_Idle(pDMC2280Driv self, pEvtEvent event) {
DMC_ClearTimer(self);
if (self->driver_status == HWBusy)
self->driver_status = HWIdle;
#ifdef RESET_RUN_ON_IDLE
if (self->variables & VAR_RUN) {
char cmd[CMDLEN];
snprintf(cmd, CMDLEN, "RUN%c=0", self->axisLabel);
(void) DMC_Send(self, cmd);
}
#endif
DMC_SetTimer(self, 0);
self->subState = 0;
return;
@@ -2063,6 +2104,11 @@ static void DMCState_MotorOn(pDMC2280Driv self, pEvtEvent event) {
change_state(self, DMCState_MotorStop);
return;
}
#endif
#ifdef SPEED_ON_MOVE
cmdSpeed(self); /* No Response */
cmdAccel(self); /* No Response */
cmdDecel(self); /* No Response */
#endif
set_lastMotion(self, self->currSteps, self->currCounts);
/* compute position for PA command */
@@ -3355,10 +3401,14 @@ static int DMC2280SetPar(void *pData, SConnection *pCon,
return 1;
}
self->speed = newValue;
#if 1
return cmdSpeed(self); /* FIXME should signal a HWFault */
#else
snprintf(cmd,CMDLEN,"SP%c=%d", self->axisLabel, motSpeed(self, self->speed));
if (FAILURE == DMC_Send(self, cmd))
return 0; /* FIXME should signal a HWFault */
return 1;
#endif
}
/* Set Acceleration */
@@ -3374,10 +3424,14 @@ static int DMC2280SetPar(void *pData, SConnection *pCon,
return 1;
}
self->accel = newValue;
#if 1
return cmdAccel(self); /* FIXME should signal a HWFault */
#else
snprintf(cmd,CMDLEN,"AC%c=%d", self->axisLabel, motAccel(self, self->accel));
if (FAILURE == DMC_Send(self, cmd))
return 0; /* FIXME should signal a HWFault */
return 1;
#endif
}
/* Set Deceleration */
@@ -3393,10 +3447,14 @@ static int DMC2280SetPar(void *pData, SConnection *pCon,
return 1;
}
self->decel = newValue;
#if 1
return cmdDecel(self); /* FIXME should signal a HWFault */
#else
snprintf(cmd,CMDLEN,"DC%c=%d", self->axisLabel, motDecel(self, self->decel));
if (FAILURE == DMC_Send(self, cmd))
return 0; /* FIXME should signal a HWFault */
return 1;
#endif
}
if (strcasecmp("hardlowerlim", name) == 0) {
/* Debug Managers only */