Skip to content

Commit

Permalink
Merge pull request #203 from epics-modules/add_accs_field_with_accu_c…
Browse files Browse the repository at this point in the history
…ontrol

Add ACCS field with ACCU control
  • Loading branch information
kmpeters authored May 22, 2023
2 parents 7c0ef61 + 7291b55 commit 04a5ee7
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 42 deletions.
30 changes: 28 additions & 2 deletions docs/motorRecord.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ <h2>Field Descriptions</h2> In addition to fields common to all record types (se
<td><br>
</td>
</tr>
<tr>
<td><a href="#Fields_motion">ACCU</a></td>
<td>R/W</td>
<td>Acceleration used</td>
<td>RECCHOICE</td>
<td>(0:"Use ACCL", 1:"Use ACCS")</td>
</tr>
<tr>
<td><a href="#Fields_status">ADEL</a></td>
<td>R/W</td>
Expand Down Expand Up @@ -1718,11 +1725,30 @@ <h2>Field Descriptions</h2> In addition to fields common to all record types (se
motor motion.</td>
</tr>
<tr>
<td colspan="5">The motor record expects the hardware to produce a trapezoidal
<td>ACCS</td>
<td>R/W</td>
<td>Acceleration (EGU/s^2)</td>
<td>DOUBLE</td>
<td>Valid range; 0 &lt;= ACCS</td>
</tr>
<tr>
<td>ACCU</td>
<td>R/W</td>
<td>Acceleration used</td>
<td>RECCHOICE</td>
<td>(0:"Use ACCL", 1:"Use ACCS")&nbsp; This field determines whether the ACCL or ACCS field
is used in the calculation of the acceleration that is sent to device support. The field
that is not used changes with VELO. The default value is "Use ACCL"&nbsp;</td>
</tr>
<tr>
<td colspan="5">
The motor record expects the hardware to produce a trapezoidal
speed profile. That is, the motor speed is expected to increase linearly with
time from the base speed, VBAS, to the full speed, VELO, in ACCL seconds. At the
end of a motion, the speed is expected to decrease similarly to VBAS.
Note that the ACCS field can be use to specify the acceleration in EGU/s^2.&nbsp;</td>
<p>Note that the ACCS field can be use to specify the acceleration in EGU/s^2.</p>
<p>Velocity and acceleration are related by the following equation: <br>
VELO - VBAS = ACCL * ACCS &nbsp;</p></td>
</tr>
<tr>
<td>JVEL</td>
Expand Down
4 changes: 4 additions & 0 deletions modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ ifdef LUA
$(ECHO) Creating $@, LUA = $(LUA)
@echo LUA = $(LUA)>> $@
endif
ifdef AUTOSAVE
$(ECHO) Creating $@, AUTOSAVE = $(AUTOSAVE)
@echo AUTOSAVE = $(AUTOSAVE)>> $@
endif
ifdef MODBUS
$(ECHO) Creating $@, MODBUS = $(MODBUS)
@echo MODBUS = $(MODBUS)>> $@
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/asyn_motor.db
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ record(motor, "$(P)$(M)") {
field(VELO, "$(VELO)")
field(VBAS, "$(VBAS)")
field(ACCL, "$(ACCL)")
field(ACCU, "$(ACCU=0)")
field(BDST, "$(BDST)")
field(BVEL, "$(BVEL)")
field(BACC, "$(BACC)")
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/asyn_motor_model2.db
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ record(motor, "$(P)$(M)") {
field(VELO, "$(VELO)")
field(VBAS, "$(VBAS)")
field(ACCL, "$(ACCL)")
field(ACCU, "$(ACCU=0)")
field(BDST, "$(BDST)")
field(BVEL, "$(BVEL)")
field(BACC, "$(BACC)")
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/basic_asyn_motor.db
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ record(motor,"$(P)$(M)")
field(VELO,"$(VELO)")
field(VBAS,"$(VBAS)")
field(ACCL,"$(ACCL)")
field(ACCU,"$(ACCU=0)")
field(BDST,"$(BDST)")
field(BVEL,"$(BVEL)")
field(BACC,"$(BACC)")
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/basic_asyn_motor_model2.db
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ record(motor,"$(P)$(M)")
field(VELO,"$(VELO)")
field(VBAS,"$(VBAS)")
field(ACCL,"$(ACCL)")
field(ACCU,"$(ACCU=0)")
field(BDST,"$(BDST)")
field(BVEL,"$(BVEL)")
field(BACC,"$(BACC)")
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/basic_motor.db
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ grecord(motor,"$(P)$(M)")
field(VELO,"$(VELO)")
field(VBAS,"$(VBAS)")
field(ACCL,"$(ACCL)")
field(ACCU,"$(ACCU=0)")
field(BDST,"$(BDST)")
field(BVEL,"$(BVEL)")
field(BACC,"$(BACC)")
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/basic_motor_settings.req
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $(P)$(M).RRES
$(P)$(M).VBAS
$(P)$(M).VELO
$(P)$(M).ACCL
$(P)$(M).ACCU
$(P)$(M).BDST
$(P)$(M).BVEL
$(P)$(M).BACC
Expand Down
1 change: 1 addition & 0 deletions motorApp/Db/motor.db
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ record(motor, "$(P)$(M)") {
field(VELO, "$(VELO)")
field(VBAS, "$(VBAS)")
field(ACCL, "$(ACCL)")
field(ACCU, "$(ACCU=0)")
field(BDST, "$(BDST)")
field(BVEL, "$(BVEL)")
field(BACC, "$(BACC)")
Expand Down
55 changes: 24 additions & 31 deletions motorApp/MotorSrc/motorRecord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static double accEGUfromVelo(motorRecord *pmr, double veloEGU)
double vmax = fabs(veloEGU);
double acc;
/* ACCL or ACCS */
if (pmr->accu == motorACCSused_Accs)
if (pmr->accu == motorACCU_Accs)
acc = pmr->accs;
else if (vmax > vmin)
acc = (vmax - vmin) / pmr->accl;
Expand All @@ -498,14 +498,9 @@ static double accEGUfromVelo(motorRecord *pmr, double veloEGU)

static void updateACCLfromACCS(motorRecord *pmr)
{
if (pmr->accu != motorACCSused_Accs)
{
pmr->accu = motorACCSused_Accs;
db_post_events(pmr, &pmr->accu, DBE_VAL_LOG);
}
if (pmr->accs > 0.0)
{
double temp_dbl = pmr->velo / pmr->accs;
double temp_dbl = (pmr->velo > pmr->vbas) ? (pmr->velo - pmr->vbas) / pmr->accs : pmr->velo / pmr->accs;
if (pmr->accl != temp_dbl)
{
pmr->accl = temp_dbl;
Expand All @@ -517,12 +512,7 @@ static void updateACCLfromACCS(motorRecord *pmr)
static void updateACCSfromACCL(motorRecord *pmr)
{
double temp_dbl;
if (pmr->accu != motorACCSused_Accl)
{
pmr->accu = motorACCSused_Accl;
db_post_events(pmr, &pmr->accu, DBE_VAL_LOG);
}
temp_dbl = pmr->velo / pmr->accl;
temp_dbl = (pmr->velo > pmr->vbas) ? (pmr->velo - pmr->vbas) / pmr->accl : pmr->velo / pmr->accl;
if (pmr->accs != temp_dbl)
{
pmr->accs = temp_dbl;
Expand All @@ -532,11 +522,11 @@ static void updateACCSfromACCL(motorRecord *pmr)

static void updateACCL_ACCSfromVELO(motorRecord *pmr)
{
if (pmr->accu == motorACCSused_Accs)
if (pmr->accu == motorACCU_Accs)
{
if (pmr->accs > 0.0)
{
double temp_dbl = pmr->velo / pmr->accs;
double temp_dbl = (pmr->velo > pmr->vbas) ? (pmr->velo - pmr->vbas) / pmr->accs : pmr->velo / pmr->accs;
if (pmr->accl != temp_dbl)
{
pmr->accl = temp_dbl;
Expand All @@ -546,7 +536,7 @@ static void updateACCL_ACCSfromVELO(motorRecord *pmr)
}
else
{
double temp_dbl = pmr->velo / pmr->accl;
double temp_dbl = (pmr->velo > pmr->vbas) ? (pmr->velo - pmr->vbas) / pmr->accl : pmr->velo / pmr->accl;
if (pmr->accs != temp_dbl)
{
pmr->accs = temp_dbl;
Expand Down Expand Up @@ -2639,6 +2629,7 @@ static long special(DBADDR *paddr, int after)
pmr->sbas = temp_dbl;
db_post_events(pmr, &pmr->sbas, DBE_VAL_LOG);
}
updateACCL_ACCSfromVELO(pmr);
break;

/* new sbas: make vbas agree */
Expand All @@ -2654,6 +2645,7 @@ static long special(DBADDR *paddr, int after)
pmr->vbas = temp_dbl;
db_post_events(pmr, &pmr->vbas, DBE_VAL_LOG);
}
updateACCL_ACCSfromVELO(pmr);
break;

/* new vmax: make smax agree */
Expand Down Expand Up @@ -2744,7 +2736,11 @@ static long special(DBADDR *paddr, int after)

/* new accs */
case motorRecordACCS:
db_post_events(pmr, &pmr->accs, DBE_VAL_LOG);
if (pmr->accs <= 0.0)
{
updateACCSfromACCL(pmr);
}
//db_post_events(pmr, &pmr->accs, DBE_VAL_LOG);
updateACCLfromACCS(pmr);
break;

Expand Down Expand Up @@ -4027,20 +4023,22 @@ static void check_speed_and_resolution(motorRecord * pmr)
db_post_events(pmr, &pmr->sbak, DBE_VAL_LOG);
db_post_events(pmr, &pmr->bvel, DBE_VAL_LOG);

if (pmr->accs && !pmr->accl)
/* ACCS (EGU/sec^2) <--> ACCL (sec) */
if (pmr->accs > 0.0)
{
/* ACCL == 0.0, ACCS is != 0.0 -> Use ACCS
This is a (possible) new way to configure a database.
Existing Db files will have ACCS == 0.0 and this
is backwards compatible and behaves as before */
updateACCLfromACCS(pmr);
}
/* Sanity check on acceleration time. */
if (pmr->accl == 0.0)
else
{
pmr->accl = 0.1;
db_post_events(pmr, &pmr->accl, DBE_VAL_LOG);
/* Sanity check on acceleration time. */
if (pmr->accl == 0.0)
{
pmr->accl = 0.1;
db_post_events(pmr, &pmr->accl, DBE_VAL_LOG);
}
updateACCSfromACCL(pmr);
}
/* Sanity check on backlash acceleration time. */
if (pmr->bacc == 0.0)
{
pmr->bacc = 0.1;
Expand All @@ -4060,11 +4058,6 @@ static void check_speed_and_resolution(motorRecord * pmr)
pmr->hvel = pmr->vbas;
else
range_check(pmr, &pmr->hvel, pmr->vbas, pmr->vmax);
/* Make sure that ACCS/ACCU are initialized */
if (pmr->accu == motorACCSused_Undef)
{
updateACCSfromACCL(pmr);
}
}

/*
Expand Down
16 changes: 7 additions & 9 deletions motorApp/MotorSrc/motorRecord.dbd
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ menu(motorRMOD) {
choice(motorRMOD_G,"Geometric")
choice(motorRMOD_I,"In-Position")
}

menu(motorRSTM) {
choice(motorRSTM_Never, "Never")
choice(motorRSTM_Always, "Always")
choice(motorRSTM_NearZero, "NearZero")
choice(motorRSTM_Conditional, "Conditional")
}

menu(motorACCSused) {
choice(motorACCSused_Undef,"Undef")
choice(motorACCSused_Accl, "Accl")
choice(motorACCSused_Accs, "Accs")
menu(motorACCU) {
choice(motorACCU_Accl, "Use ACCL")
choice(motorACCU_Accs, "Use ACCS")
}

include "menuOmsl.dbd"
Expand Down Expand Up @@ -195,9 +192,10 @@ recordtype(motor) {
interest(1)
}
field(ACCU,DBF_MENU) {
prompt("ACCS used")
special(SPC_NOMOD)
menu(motorACCSused)
prompt("Acceleration used")
special(SPC_MOD)
menu(motorACCU)
initial("0")
}
field(BDST,DBF_DOUBLE) {
prompt("BL Distance (EGU)")
Expand Down

0 comments on commit 04a5ee7

Please sign in to comment.