Enabled autosave on asynMotor to restore DVAL after power cycle by writing new

init_controller routine and calling LOAD_POS
This commit is contained in:
Peter Denison
2007-02-03 12:07:17 +00:00
parent ae87fbc0fb
commit b40820e90b
2 changed files with 46 additions and 10 deletions
+10 -8
View File
@@ -2,9 +2,9 @@
FILENAME... drvMotorSim.c
USAGE... Simulated Motor Support.
Version: $Revision: 1.6 $
Version: $Revision: 1.7 $
Modified By: $Author: peterd $
Last Modified: $Date: 2006-08-10 08:12:47 $
Last Modified: $Date: 2007-02-03 12:07:17 $
*/
/*
@@ -105,28 +105,28 @@ static motorSim_t drv={ NULL, NULL, motorSimLogMsg, NULL, { 0, 0 } };
static void motorAxisReportAxis( AXIS_HDL pAxis, int level )
{
printf( "Found driver for motorSim card %d, axis %d", pAxis->card, pAxis->axis );
printf( "Found driver for motorSim card %d, axis %d\n", pAxis->card, pAxis->axis );
if (level > 0)
{
double lowSoftLimit=0.0;
double hiSoftLimit=0.0;
printf( "Current position = %f, velocity = %f at current time: %f",
printf( "Current position = %f, velocity = %f at current time: %f\n",
pAxis->nextpoint.axis[0].p,
pAxis->nextpoint.axis[0].v,
pAxis->nextpoint.T );
printf( "Destination posn = %f, velocity = %f at desination time: %f",
printf( "Destination posn = %f, velocity = %f at desination time: %f\n",
pAxis->endpoint.axis[0].p,
pAxis->endpoint.axis[0].v,
pAxis->endpoint.T );
printf( "Hard limits: %f, %f", pAxis->lowHardLimit, pAxis->hiHardLimit );
printf( "Hard limits: %f, %f\n", pAxis->lowHardLimit, pAxis->hiHardLimit );
motorParam->getDouble( pAxis->params, motorAxisHighLimit, &hiSoftLimit );
motorParam->getDouble( pAxis->params, motorAxisLowLimit, &lowSoftLimit );
printf( "Soft limits: %f, %f", lowSoftLimit, hiSoftLimit );
printf( "Soft limits: %f, %f\n", lowSoftLimit, hiSoftLimit );
if (pAxis->homing) printf( "Currently homing axis" );
if (pAxis->homing) printf( "Currently homing axis\n" );
motorParam->dump( pAxis->params );
}
@@ -543,6 +543,7 @@ static int motorSimCreateAxis( motorSim_t * pDrv, int card, int axis, double low
{
AXIS_HDL pAxis;
AXIS_HDL * ppLast = &(pDrv->pFirst);
start=0;
for ( pAxis = pDrv->pFirst;
pAxis != NULL &&
@@ -569,6 +570,7 @@ static int motorSimCreateAxis( motorSim_t * pDrv, int card, int axis, double low
pAxis->endpoint.T = 0;
pAxis->endpoint.axis[0].p = start;
pAxis->endpoint.axis[0].v = 0;
pAxis->nextpoint.axis[0].p = start;
if ((pAxis->route = routeNew( &(pAxis->endpoint), &pars )) != NULL &&
(pAxis->params = motorParam->create( 0, MOTOR_AXIS_NUM_PARAMS )) != NULL &&
+36 -2
View File
@@ -11,9 +11,9 @@
* Notwithstanding the above, explicit permission is granted for APS to
* redistribute this software.
*
* Version: $Revision: 1.15 $
* Version: $Revision: 1.16 $
* Modified by: $Author: peterd $
* Last Modified: $Date: 2007-02-02 13:50:46 $
* Last Modified: $Date: 2007-02-03 12:07:17 $
*
* Original Author: Peter Denison
* Current Author: Peter Denison
@@ -30,6 +30,7 @@
#include <recSup.h>
#include <devSup.h>
#include <alarm.h>
#include <epicsEvent.h>
#include <cantProceed.h> /* !! for callocMustSucceed() */
#include <asynDriver.h>
@@ -94,6 +95,7 @@ typedef struct
asynMotorStatus *pasynMotorStatus;
void *asynMotorStatusPvt;
void *registrarPvt;
epicsEventId initEvent;
} motorAsynPvt;
@@ -106,6 +108,34 @@ static long init( int after )
return 0;
}
static void init_controller(struct motorRecord *pmr )
{
/* This routine is copied out of the old motordevCom and initialises the controller
based on the record values. I think most of it should be transferred to init_record
which is one reason why I have separated it into another routine */
motorAsynPvt *pPvt = (motorAsynPvt *)pmr->dpvt;
double position = pPvt->status.position;
if ((fabs(pmr->dval) > pmr->rdbd && pmr->mres != 0) &&
((position * pmr->mres) < pmr->rdbd))
{
double setPos = pmr->dval / pmr->mres;
epicsEventId initEvent = epicsEventCreate( epicsEventEmpty );
pPvt->initEvent = initEvent;
start_trans(pmr);
build_trans(LOAD_POS, &setPos, pmr);
end_trans(pmr);
if ( initEvent )
{
epicsEventMustWait(initEvent);
epicsEventDestroy(initEvent);
}
}
}
static long init_record(struct motorRecord * pmr )
{
asynUser *pasynUser;
@@ -221,6 +251,8 @@ static long init_record(struct motorRecord * pmr )
pasynManager->freeAsynUser(pasynUser);
pPvt->needUpdate = 1;
init_controller(pmr);
return(0);
bad:
pmr->pact=1;
@@ -470,6 +502,8 @@ static void asynCallback(asynUser *pasynUser)
"devMotorAsyn::asynCallback: %s error in freeAsynUser, %s\n",
pmr->name, pasynUser->errorMessage);
}
if ( pPvt->initEvent ) epicsEventSignal( pPvt->initEvent );
}
/**