From 4277772b0ea9e3443fa9a0b6a99e66f9f70df80f Mon Sep 17 00:00:00 2001 From: Ron Sluiter Date: Fri, 12 Dec 2003 21:53:10 +0000 Subject: [PATCH] Converted MSTA #define's to bit field. --- motorApp/OmsSrc/devOmsCom.cc | 9 ++- motorApp/OmsSrc/drvOms.cc | 92 +++++++++++--------------- motorApp/OmsSrc/drvOms58.cc | 107 ++++++++++++++++--------------- motorApp/SoftMotorSrc/devSoft.cc | 26 ++++++-- 4 files changed, 120 insertions(+), 114 deletions(-) diff --git a/motorApp/OmsSrc/devOmsCom.cc b/motorApp/OmsSrc/devOmsCom.cc index 6077c64e..eaf57c7a 100644 --- a/motorApp/OmsSrc/devOmsCom.cc +++ b/motorApp/OmsSrc/devOmsCom.cc @@ -2,9 +2,9 @@ FILENAME... devOmsCom.cc USAGE... Data and functions common to all OMS device level support. -Version: $Revision: 1.3 $ +Version: $Revision: 1.4 $ Modified By: $Author: sluiter $ -Last Modified: $Date: 2003-06-16 15:04:11 $ +Last Modified: $Date: 2003-12-12 21:48:45 $ */ /* @@ -243,6 +243,8 @@ long oms_build_trans(motor_cmnd command, double *parms, struct motorRecord *mr) trans->state = IDLE_STATE; /* No command sent to the controller. */ else { + msta_field msta; + /* Silently enforce minimum range on KP command. */ if (command == SET_PGAIN && *parms < 0.00005) { @@ -348,7 +350,8 @@ errorexit: errMessage(-1, "Invalid device directive"); } /* Code to hide Oms58 moving off limit switch problem. */ - if (((mr->msta & RA_PLUS_LS) || (mr->msta & RA_MINUS_LS)) && + msta.All = mr->msta; + if ((msta.Bits.RA_PLUS_LS || msta.Bits.RA_MINUS_LS) && (command == MOVE_ABS || command == MOVE_REL)) { if (mr->rdif >= 0) diff --git a/motorApp/OmsSrc/drvOms.cc b/motorApp/OmsSrc/drvOms.cc index 02a37d65..57e51a9e 100644 --- a/motorApp/OmsSrc/drvOms.cc +++ b/motorApp/OmsSrc/drvOms.cc @@ -2,9 +2,9 @@ FILENAME... drvOms.cc USAGE... Driver level support for OMS models VME8, VME44 and VS4. -Version: $Revision: 1.12 $ +Version: $Revision: 1.13 $ Modified By: $Author: sluiter $ -Last Modified: $Date: 2003-12-03 19:12:35 $ +Last Modified: $Date: 2003-12-12 21:52:55 $ */ /* @@ -54,7 +54,12 @@ Last Modified: $Date: 2003-12-03 19:12:35 $ * - changed omsGet() timeout argument to type bool. * - changed recv_rng and send_rng from C to C++ interface. * .05 12-03-03 rls - update rate bug fix. - * + * .06 12-12-03 rls - Converted MSTA #define's to bit field. + * - Two lines of code must be selected based on either + * Tornado 2.0.2 (default) or Tornado 2.2. If Tornado + * 2.2 is selected, EPICS base patches must be applied as + * described in; + * http://www.aps.anl.gov/upd/people/sluiter/epics/motor/R5-2/Problems.html */ /*========================stepper motor driver ======================== @@ -212,7 +217,7 @@ static void query_done(int card, int axis, struct mess_node *nodeptr) send_mess(card, DONE_QUERY, oms_axis[axis]); recv_mess(card, buffer, 1); - if (nodeptr->status & RA_PROBLEM) + if (nodeptr->status.Bits.RA_PROBLEM) send_mess(card, AXIS_STOP, oms_axis[axis]); } @@ -228,9 +233,11 @@ static int set_status(int card, int signal) int index, pos; int rtn_state; bool ls_active; + msta_field status; motor_info = &(motor_state[card]->motor_info[signal]); nodeptr = motor_info->motor_motion; + status.All = motor_info->status.All; if (motor_state[card]->motor_info[signal].encoder_present == YES) { @@ -254,35 +261,25 @@ static int set_status(int card, int signal) case 0: /* axis status */ ax_stat = (struct axis_status *) p; - if (ax_stat->direction == 'P') - motor_info->status |= RA_DIRECTION; - else - motor_info->status &= ~RA_DIRECTION; - - if (ax_stat->done == 'D') - motor_info->status |= RA_DONE; - else - motor_info->status &= ~RA_DONE; + status.Bits.RA_DIRECTION = (ax_stat->direction == 'P') ? 1 : 0; + status.Bits.RA_DONE = (ax_stat->done == 'D') ? 1 : 0; + status.Bits.RA_HOME = (ax_stat->home == 'H') ? 1 : 0; if (ax_stat->overtravel == 'L') { ls_active = true; - if (motor_info->status & RA_DIRECTION) - motor_info->status |= RA_PLUS_LS; + if (status.Bits.RA_DIRECTION) + status.Bits.RA_PLUS_LS = 1; else - motor_info->status |= RA_MINUS_LS; + status.Bits.RA_MINUS_LS = 1; } else { ls_active = false; - motor_info->status &= ~(RA_PLUS_LS | RA_MINUS_LS); + status.Bits.RA_PLUS_LS = 0; + status.Bits.RA_MINUS_LS = 0; } - if (ax_stat->home == 'H') - motor_info->status |= RA_HOME; - else - motor_info->status &= ~RA_HOME; - break; case 1: /* motor pulse count (position) */ sscanf(p, "%index", &pos); @@ -294,14 +291,14 @@ static int set_status(int card, int signal) if (motor_info->no_motion_count > motionTO) { - motor_info->status |= RA_PROBLEM; + status.Bits.RA_PROBLEM = 1; send_mess(card, AXIS_STOP, oms_axis[signal]); motor_info->no_motion_count = 0; errlogSevPrintf(errlogMinor, "Motor motion timeout ERROR on card: %d, signal: %d\n", card, signal); } else - motor_info->status &= ~RA_PROBLEM; + status.Bits.RA_PROBLEM = 0; motor_info->position = pos; break; @@ -315,27 +312,10 @@ static int set_status(int card, int signal) break; case 3: /* encoder status */ en_stat = (struct encoder_status *) p; - - if (en_stat->slip_enable == 'E') - motor_info->status |= EA_SLIP; - else - motor_info->status &= ~EA_SLIP; - - if (en_stat->pos_enable == 'E') - motor_info->status |= EA_POSITION; - else - motor_info->status &= ~EA_POSITION; - - if (en_stat->slip_detect == 'S') - motor_info->status |= EA_SLIP_STALL; - else - motor_info->status &= ~EA_SLIP_STALL; - - if (en_stat->axis_home == 'H') - motor_info->status |= EA_HOME; - else - motor_info->status &= ~EA_HOME; - + status.Bits.EA_SLIP = (en_stat->slip_enable == 'E') ? 1 : 0; + status.Bits.EA_POSITION = (en_stat->pos_enable == 'E') ? 1 : 0; + status.Bits.EA_SLIP_STALL = (en_stat->slip_detect == 'S') ? 1 : 0; + status.Bits.EA_HOME = (en_stat->axis_home == 'H') ? 1 : 0; break; default: break; @@ -348,19 +328,19 @@ static int set_status(int card, int signal) * time to request additional information so the velocity is set to * indicate moving or not-moving. */ - if (motor_info->status & RA_DONE) + if (status.Bits.RA_DONE) motor_info->velocity = 0; else motor_info->velocity = 1; - if (!(motor_info->status & RA_DIRECTION)) + if (!(status.Bits.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; + status.Bits.RA_DONE | status.Bits.RA_PROBLEM) ? 1 : 0; /* Test for post-move string. */ - if ((motor_info->status & RA_DONE || ls_active == true) && (nodeptr != 0) && + if ((status.Bits.RA_DONE || ls_active == true) && (nodeptr != 0) && (nodeptr->postmsgptr != 0)) { char buffer[40]; @@ -418,6 +398,8 @@ errorexit: errMessage(-1, "Invalid device directive"); send_mess(card, outbuf, oms_axis[signal]); nodeptr->postmsgptr = NULL; } + + motor_info->status.All = status.All; /* Update status from local copy. */ return (rtn_state); } @@ -876,7 +858,8 @@ static int motorIsrEnable(int card) pmotor = (struct vmex_motor *) (pmotorState->localaddr); status = devConnectInterrupt(intVME, omsInterruptVector + card, - (void (*)()) motorIsr, (void *) card); + (void (*)()) motorIsr, (void *) card);// Tornado 2.0.2 +// Tornado 2.2 (devLibVOIDFUNCPTR) motorIsr, (void *) card); if (!RTN_SUCCESS(status)) { @@ -936,7 +919,8 @@ static void motorIsrDisable(int card) pmotor->control = 0; status = devDisconnectInterrupt(intVME, omsInterruptVector + card, - (void (*)()) motorIsr); + (void (*)()) motorIsr);// Tornado 2.0.2 +// Tornado 2.2 (devLibVOIDFUNCPTR) motorIsr); if (!RTN_SUCCESS(status)) errPrintf(status, __FILE__, __LINE__, "Can't disconnect vector %d\n", omsInterruptVector + card); @@ -1110,7 +1094,7 @@ static int motor_init() pos_ptr = strtok_r(NULL, ",", &tok_save), total_axis++) { pmotorState->motor_info[total_axis].motor_motion = NULL; - pmotorState->motor_info[total_axis].status = 0; + pmotorState->motor_info[total_axis].status.All = 0; } Debug(3, "Total axis = %d\n", total_axis); @@ -1144,13 +1128,13 @@ static int motor_init() for (motor_index = 0; motor_index < total_axis; motor_index++) { - pmotorState->motor_info[motor_index].status = 0; + pmotorState->motor_info[motor_index].status.All = 0; pmotorState->motor_info[motor_index].no_motion_count = 0; pmotorState->motor_info[motor_index].encoder_position = 0; pmotorState->motor_info[motor_index].position = 0; if (pmotorState->motor_info[motor_index].encoder_present == YES) - pmotorState->motor_info[motor_index].status |= EA_PRESENT; + pmotorState->motor_info[motor_index].status.Bits.EA_PRESENT = 1; set_status(card_index, motor_index); } diff --git a/motorApp/OmsSrc/drvOms58.cc b/motorApp/OmsSrc/drvOms58.cc index a021c876..83a73c8b 100644 --- a/motorApp/OmsSrc/drvOms58.cc +++ b/motorApp/OmsSrc/drvOms58.cc @@ -2,9 +2,9 @@ FILENAME... drvOms58.cc USAGE... Motor record driver level support for OMS model VME58. -Version: $Revision: 1.7 $ +Version: $Revision: 1.8 $ Modified By: $Author: sluiter $ -Last Modified: $Date: 2003-10-28 16:41:14 $ +Last Modified: $Date: 2003-12-12 21:52:53 $ */ /* @@ -73,6 +73,12 @@ Last Modified: $Date: 2003-10-28 16:41:14 $ * boards after the "hole" to work. * .23 06-04-03 rls Convert to R3.14.x. * .24 06-04-03 rls extended device directive support to PREM and POST. + * .25 12-12-03 rls - Converted MSTA #define's to bit field. + * - One line of code must be selected based on either + * Tornado 2.0.2 (default) or Tornado 2.2. If Tornado + * 2.2 is selected, EPICS base patches must be applied as + * described in; + * http://www.aps.anl.gov/upd/people/sluiter/epics/motor/R5-2/Problems.html */ #include @@ -232,7 +238,7 @@ STATIC void query_done(int card, int axis, struct mess_node *nodeptr) taskDelay(1); /* Work around for intermittent wrong LS status. */ #endif - if (nodeptr->status & RA_PROBLEM) + if (nodeptr->status.Bits.RA_PROBLEM) send_mess(card, AXIS_STOP, oms58_axis[axis]); } @@ -345,25 +351,30 @@ STATIC int set_status(int card, int signal) struct encoder_status *en_stat; char q_buf[50], outbuf[50]; int index; - bool ls_active; + bool ls_active = false; + bool got_encoder; + msta_field status; int rtn_state; motor_info = &(motor_state[card]->motor_info[signal]); nodeptr = motor_info->motor_motion; pmotor = (struct vmex_motor *) motor_state[card]->localaddr; + status.All = motor_info->status.All; if (motor_state[card]->motor_info[signal].encoder_present == YES) { /* get 4 peices of info from axis */ send_mess(card, ALL_INFO, oms58_axis[signal]); recv_mess(card, q_buf, 2); + got_encoder = true; } else { /* get 2 peices of info from axis */ send_mess(card, AXIS_INFO, oms58_axis[signal]); recv_mess(card, q_buf, 1); + got_encoder = false; } for (index = 0, p = strtok_r(q_buf, ",", &tok_save); p; @@ -374,63 +385,41 @@ STATIC int set_status(int card, int signal) case 0: /* axis status */ ax_stat = (struct axis_status *) p; - if (ax_stat->direction == 'P') - motor_info->status |= RA_DIRECTION; - else - motor_info->status &= ~RA_DIRECTION; + status.Bits.RA_DIRECTION = (ax_stat->direction == 'P') ? 1 : 0; + status.Bits.RA_HOME = (ax_stat->home == 'H') ? 1 : 0; if (ax_stat->done == 'D') { /* Request Data Area Update after DONE detected so that both * ASCII command data and shared memory data match. */ start_status(card); - motor_info->status |= RA_DONE; + status.Bits.RA_DONE = 1; } else - motor_info->status &= ~RA_DONE; + status.Bits.RA_DONE = 0; if (ax_stat->overtravel == 'L') { ls_active = true; - if (motor_info->status & RA_DIRECTION) - motor_info->status |= RA_PLUS_LS; + if (status.Bits.RA_DIRECTION) + status.Bits.RA_PLUS_LS = 1; else - motor_info->status |= RA_MINUS_LS; + status.Bits.RA_MINUS_LS = 1; } else { ls_active = false; - motor_info->status &= ~(RA_PLUS_LS | RA_MINUS_LS); + status.Bits.RA_PLUS_LS = 0; + status.Bits.RA_MINUS_LS = 0; } - - if (ax_stat->home == 'H') - motor_info->status |= RA_HOME; - else - motor_info->status &= ~RA_HOME; - break; case 1: /* encoder status */ en_stat = (struct encoder_status *) p; - if (en_stat->slip_enable == 'E') - motor_info->status |= EA_SLIP; - else - motor_info->status &= ~EA_SLIP; - - if (en_stat->pos_enable == 'E') - motor_info->status |= EA_POSITION; - else - motor_info->status &= ~EA_POSITION; - - if (en_stat->slip_detect == 'S') - motor_info->status |= EA_SLIP_STALL; - else - motor_info->status &= ~EA_SLIP_STALL; - - if (en_stat->axis_home == 'H') - motor_info->status |= EA_HOME; - else - motor_info->status &= ~EA_HOME; + status.Bits.EA_SLIP = (en_stat->slip_enable == 'E') ? 1 : 0; + status.Bits.EA_POSITION = (en_stat->pos_enable == 'E') ? 1 : 0; + status.Bits.EA_SLIP_STALL = (en_stat->slip_detect == 'S') ? 1 : 0; + status.Bits.EA_HOME = (en_stat->axis_home == 'H') ? 1 : 0; break; default: break; @@ -461,21 +450,21 @@ STATIC int set_status(int card, int signal) if (motor_info->no_motion_count > motionTO) { - motor_info->status |= RA_PROBLEM; + status.Bits.RA_PROBLEM = 1; send_mess(card, AXIS_STOP, oms58_axis[signal]); motor_info->no_motion_count = 0; errlogSevPrintf(errlogMinor, "Motor motion timeout ERROR on card: %d, signal: %d\n", card, signal); } else - motor_info->status &= ~RA_PROBLEM; + status.Bits.RA_PROBLEM = 0; /* get command velocity - word access only */ motorData = pack2x16(pmotorData->cmndVel); motor_info->velocity = motorData; - if (!(motor_info->status & RA_DIRECTION)) + if (!(status.Bits.RA_DIRECTION)) motor_info->velocity *= -1; /* Get encoder position */ @@ -493,7 +482,8 @@ STATIC int set_status(int card, int signal) bitselect = (1 << signal); if ((inputs & bitselect) == 0) { - motor_info->status |= (RA_PLUS_LS | RA_MINUS_LS); + status.Bits.RA_PLUS_LS = 1; /* Turn on both limit switches. */ + status.Bits.RA_MINUS_LS = 1; logMsg((char *) "Drive power failure at VME58 card#%d motor#%d\n", card, signal, 0, 0, 0, 0); } @@ -501,10 +491,10 @@ STATIC int set_status(int card, int signal) } rtn_state = (!motor_info->no_motion_count || ls_active == true || - (motor_info->status & (RA_DONE | RA_PROBLEM))) ? 1 : 0; + status.Bits.RA_DONE | status.Bits.RA_PROBLEM) ? 1 : 0; /* Test for post-move string. */ - if ((motor_info->status & RA_DONE || ls_active == true) && nodeptr != 0 && + if ((status.Bits.RA_DONE || ls_active == true) && nodeptr != 0 && nodeptr->postmsgptr != 0) { char buffer[40]; @@ -563,6 +553,19 @@ errorexit: errMessage(-1, "Invalid device directive"); nodeptr->postmsgptr = NULL; } + /* Bug fix for DC servo moving away from limit switch, but move is not far enough to + * get off limit switch; resulting in limit error. Fix is to force CDIR to match + * MSTA.RA_DIRECTION. + */ + if (ls_active == true && status.Bits.GAIN_SUPPORT && status.Bits.EA_POSITION == 0) + { + struct motorRecord *mr = (struct motorRecord *) nodeptr->mrecord; + + if (mr->cdir != (short) status.Bits.RA_DIRECTION) + mr->cdir = status.Bits.RA_DIRECTION; + } + + motor_info->status.All = status.All; /* Update status from local copy. */ return (rtn_state); } @@ -921,7 +924,8 @@ STATIC int motorIsrSetup(int card) pmotor = (struct vmex_motor *) (motor_state[card]->localaddr); status = devConnectInterrupt(intVME, omsInterruptVector + card, - (void (*)()) motorIsr, (void *) card); +// Tornado 2.0.2 (void (*)()) motorIsr, (void *) card); + (devLibVOIDFUNCPTR) motorIsr, (void *) card);// Tornado 2.2 if (!RTN_SUCCESS(status)) { errPrintf(status, __FILE__, __LINE__, "Can't connect to vector %d\n", omsInterruptVector + card); @@ -1019,7 +1023,8 @@ STATIC int motor_init() Debug(9, "motor_init: devRegisterAddress() status = %d\n", (int) status); if (!RTN_SUCCESS(status)) { - errPrintf(status, __FILE__, __LINE__, "Can't register address 0x%x\n", probeAddr); + errPrintf(status, __FILE__, __LINE__, "Can't register address 0x%x\n", + (unsigned int) probeAddr); return (ERROR); } @@ -1051,7 +1056,7 @@ STATIC int motor_init() pos_ptr; pos_ptr = strtok_r(NULL, ",", &tok_save), total_axis++) { pmotorState->motor_info[total_axis].motor_motion = NULL; - pmotorState->motor_info[total_axis].status = 0; + pmotorState->motor_info[total_axis].status.All = 0; } Debug(3, "motor_init: Total axis = %d\n", total_axis); @@ -1112,15 +1117,15 @@ STATIC int motor_init() start_status(card_index); for (motor_index = 0; motor_index < total_axis; motor_index++) { - pmotorState->motor_info[motor_index].status = 0; + pmotorState->motor_info[motor_index].status.All = 0; pmotorState->motor_info[motor_index].no_motion_count = 0; pmotorState->motor_info[motor_index].encoder_position = 0; pmotorState->motor_info[motor_index].position = 0; if (pmotorState->motor_info[motor_index].encoder_present == YES) - pmotorState->motor_info[motor_index].status |= EA_PRESENT; + pmotorState->motor_info[motor_index].status.Bits.EA_PRESENT = 1; if (pmotorState->motor_info[motor_index].pid_present == YES) - pmotorState->motor_info[motor_index].status |= GAIN_SUPPORT; + pmotorState->motor_info[motor_index].status.Bits.GAIN_SUPPORT = 1; set_status(card_index, motor_index); diff --git a/motorApp/SoftMotorSrc/devSoft.cc b/motorApp/SoftMotorSrc/devSoft.cc index dac787fc..fe43c92c 100644 --- a/motorApp/SoftMotorSrc/devSoft.cc +++ b/motorApp/SoftMotorSrc/devSoft.cc @@ -2,9 +2,9 @@ FILENAME... devSoft.cc USAGE... Motor record device level support for Soft channel. -Version: $Revision: 1.6 $ +Version: $Revision: 1.7 $ Modified By: $Author: sluiter $ -Last Modified: $Date: 2003-06-16 15:03:12 $ +Last Modified: $Date: 2003-12-12 21:53:10 $ */ /* @@ -83,6 +83,7 @@ epicsExportAddress(dset,devMotorSoft); STATIC CALLBACK_VALUE update(struct motorRecord *mr) { struct soft_private *ptr = (struct soft_private *) mr->dpvt; + msta_field status; #ifdef DMR_SOFTMOTOR_MODS if (ptr->load_position) @@ -92,10 +93,14 @@ STATIC CALLBACK_VALUE update(struct motorRecord *mr) ptr->load_position = FALSE; } #endif + + status.All = mr->msta; + if (ptr->dinp_value == SOFTMOVE || ptr->dinp_value == HARDMOVE) - mr->msta &= ~RA_DONE; + status.Bits.RA_DONE = 0; else - mr->msta |= RA_DONE; + status.Bits.RA_DONE = 1; + mr->msta = status.All; return(ptr->callback_flag); } @@ -111,7 +116,13 @@ STATIC RTN_STATUS end(struct motorRecord *mr) struct soft_private *ptr = (struct soft_private *) mr->dpvt; if (ptr->default_done_behavior == YES) - mr->msta = RA_DONE; + { + msta_field status; + + status.All = 0; + status.Bits.RA_DONE = 1; + mr->msta = status.All; + } return(OK); } @@ -140,12 +151,15 @@ STATIC RTN_STATUS build(motor_cmnd command, double *parms, struct motorRecord *m case LOAD_POS: { struct soft_private *ptr = (struct soft_private *) mr->dpvt; + msta_field msta; #ifdef DMR_SOFTMOTOR_MODS ptr->load_position = TRUE; ptr->new_position = *parms; #endif - mr->msta = RA_DONE; + msta.All = 0; + msta.Bits.RA_DONE = 1; + mr->msta = msta.All; callbackRequest(&ptr->callback); } break;