Skip to content

Commit

Permalink
Merge pull request #60 from ISISComputingGroup/Ticket7821_mclennan_ad…
Browse files Browse the repository at this point in the history
…ditions

Ticket7821 mclennan additions
  • Loading branch information
FreddieAkeroyd authored Jun 2, 2023
2 parents e4d2f85 + 45a1645 commit 407a34f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 42 deletions.
31 changes: 19 additions & 12 deletions motorApp/MclennanSrc/devPM304.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@

#define STATIC static

#define HOME_MODE_BUILTIN 0
#define HOME_MODE_CONST_VELOCITY_MOVE 1
#define HOME_MODE_REVERSE_HOME_AND_ZERO 2
#define HOME_MODE_CONST_VELOCITY_MOVE_AND_ZERO 3
#define HOME_MODE_FORWARD_HOME_AND_ZERO 4

extern struct driver_table PM304_access;

#define NINT(f) (long)((f)>0 ? (f)+0.5 : (f)-0.5)
Expand Down Expand Up @@ -183,17 +177,30 @@ STATIC void request_home(struct mess_node *motor_call, int model, int axis, int
sprintf(buff, "%dIX%d;", axis, home_direction);
} else {
// datum mode: [0] = encoder index input polarity, [3] automatic direction search, [4] automatic opposite limit search
if ( home_mode==HOME_MODE_BUILTIN || home_mode==HOME_MODE_REVERSE_HOME_AND_ZERO || home_mode==HOME_MODE_FORWARD_HOME_AND_ZERO) {
datum_mode[1] = '0'; // set datum mode to capture only on HD command
if ( home_mode==HOME_MODE_REVERSE_HOME_AND_ZERO ) {
if ( home_mode==HOME_MODE_BUILTIN || home_mode==HOME_MODE_REVERSE_HOME_AND_ZERO || home_mode==HOME_MODE_FORWARD_HOME_AND_ZERO ||
home_mode==HOME_MODE_FORWARD_LIMIT_REVERSE_HOME_AND_ZERO || home_mode==HOME_MODE_REVERSE_LIMIT_FORWARD_HOME_AND_ZERO ) {
datum_mode[1] = '0'; // set datum mode to capture only once on HD command
if ( home_mode==HOME_MODE_BUILTIN ) {
datum_mode[3] = '0'; // set datum mode to no automatic direction search, will use passed home_direction
datum_mode[4] = '0'; // no auto opposite limit search
} else if ( home_mode==HOME_MODE_REVERSE_HOME_AND_ZERO||home_mode==HOME_MODE_FORWARD_LIMIT_REVERSE_HOME_AND_ZERO ) {
sprintf(buff, "%dSH0;", axis); // define home position as 0
datum_mode[2] = '1'; // set datum mode to apply home position
datum_mode[2] = '1'; // set datum mode to apply home position from SH
datum_mode[3] = '0'; // set datum mode to no automatic direction search
datum_mode[4] = '0'; // disablke auto limit search
home_direction = -1;
} else if ( home_mode==HOME_MODE_FORWARD_HOME_AND_ZERO ) {
} else if ( home_mode==HOME_MODE_FORWARD_HOME_AND_ZERO||home_mode==HOME_MODE_REVERSE_LIMIT_FORWARD_HOME_AND_ZERO ) {
sprintf(buff, "%dSH0;", axis); // define home position as 0
datum_mode[2] = '1'; // set datum mode to apply home position
datum_mode[2] = '1'; // set datum mode to apply home position from SH
datum_mode[3] = '0'; // set datum mode to no automatic direction search
datum_mode[4] = '0'; // disable auto limit search
home_direction = 1;
}
if (home_mode==HOME_MODE_FORWARD_LIMIT_REVERSE_HOME_AND_ZERO||home_mode==HOME_MODE_REVERSE_LIMIT_FORWARD_HOME_AND_ZERO){
datum_mode[4] = '1'; // enable auto limit search
}
strcat(motor_call->message, buff);
sprintf(buff, "%dCD;", axis);
strcat(motor_call->message, buff);
sprintf(buff, "%dDM%s;", axis, datum_mode);
strcat(motor_call->message, buff);
Expand Down
70 changes: 40 additions & 30 deletions motorApp/MclennanSrc/drvPM304.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static long report(int level)
printf(" reset before move %s\n", (cntrl->reset_before_move ? "YES" : "NO"));
printf(" creep speed %d\n", cntrl->creep_speeds[motor_index]);
printf(" use encoder %s\n", (cntrl->use_encoder[motor_index] ? "YES" : "NO"));
printf(" home mode %d\n", cntrl->home_mode[motor_index]);
printf(" home mode %d (%s)\n", cntrl->home_mode[motor_index], home_mode_name[cntrl->home_mode[motor_index]]);
printf(" control mode %d\n", cntrl->control_mode[motor_index]);
printf(" current op %s\n", cntrl->current_op[motor_index]);
printDatumMode(cntrl->datum_mode[motor_index]);
Expand Down Expand Up @@ -289,14 +289,34 @@ STATIC int set_status(int card, int signal)
nodeptr = motor_info->motor_motion;
status.All = motor_info->status.All;

status.Bits.RA_PLUS_LS = 0;
status.Bits.RA_MINUS_LS = 0;

bool homing = false;
if (cntrl->model != MODEL_PM304) {
char *op;
sprintf(command, "%dCO", signal+1);
send_recv_mess(card, command, response, sizeof(response));
Debug(2, "set_status, operation query, card %d, response=%s\n", card, response);
/* returns 01:XXX */
op = strchr(response, ':');
if (op != NULL) {
// work out if we are homing to datum. This is so we can not flag a hard limit explicitly
// as that may affect a move to limit done as part of a home operation
if (strstr(op + 1, "Home") != NULL) {
homing = true;
}
if (strncmp(cntrl->current_op[signal], op + 1, sizeof(cntrl->current_op[0]))) {
Debug(1, "set_status: card %d axis %d: %s\n", card, signal + 1, op + 1);
strncpy(cntrl->current_op[signal], op + 1, sizeof(cntrl->current_op[0]));
}
}
}

/* Request the status of this motor */
sprintf(command, "%dOS;", signal+1);
send_recv_mess(card, command, response, sizeof(response));
Debug(2, "set_status, status query, card %d, response=%s\n", card, response);

status.Bits.RA_PLUS_LS = 0;
status.Bits.RA_MINUS_LS = 0;

if (cntrl->model == MODEL_PM304) {
/* The response string is an eight character string of ones and zeroes */

Expand Down Expand Up @@ -327,7 +347,7 @@ STATIC int set_status(int card, int signal)
status.Bits.RA_DIRECTION = 0;
ls_active = true;
}
status.Bits.EA_HOME = 0;
status.Bits.EA_HOME = status.Bits.RA_HOME = 0;
} else {
/* The response string is 01: followed by an eight character string of ones and zeroes */
strcpy(response, &response[3]);
Expand All @@ -341,35 +361,25 @@ STATIC int set_status(int card, int signal)

status.Bits.RA_PROBLEM = (response[1] == '1') ? 1 : 0;

if (response[2] == '1') {
status.Bits.RA_PLUS_LS = 1; /* need to set ls_active = true; ? */
// we do not want to set ls_active = true when we hit a limit. This is because it will end
// motion which we do not want to do if we are doing a hardware "move to limit + home to datum" operation
// however see https://epics.anl.gov/tech-talk/2014/msg01260.php
if (response[2] == '1' && !homing) {
status.Bits.RA_PLUS_LS = 1;
}
if (response[3] == '1') {
status.Bits.RA_MINUS_LS = 1; /* need to set ls_active = true; ? */
if (response[3] == '1' && !homing) {
status.Bits.RA_MINUS_LS = 1;
}

// response[5] seems to be 1 all the time. Feels like you should be able
// to set the ATHOME bits based on it, but seems not. Maybe it refers to
// which side iof the signal you are on etc. as opposed to the transition
}

if (cntrl->model != MODEL_PM304) {
char *op;
sprintf(command, "%dCO", signal+1);
send_recv_mess(card, command, response, sizeof(response));
Debug(2, "set_status, operation query, card %d, response=%s\n", card, response);
/* returns 01:XXX */
op = strchr(response, ':');
if (op != NULL) {
if (strncmp(cntrl->current_op[signal], op + 1, sizeof(cntrl->current_op[0]))) {
Debug(1, "set_status: card %d axis %d: %s\n", card, signal + 1, op + 1);
strncpy(cntrl->current_op[signal], op + 1, sizeof(cntrl->current_op[0]));
}
int datum = response[5] - '0';
if (datum != cntrl->datum[signal]) {
Debug(1, "set_status: card %d axis %d: %s datum sensor point\n", card, signal + 1, (datum == 1 ? "ON" : "NOT ON"));
cntrl->datum[signal] = datum;
}
status.Bits.EA_HOME = status.Bits.RA_HOME = datum;
}


/* encoder status */
status.Bits.EA_HOME = 0;
status.Bits.EA_SLIP = 0;
status.Bits.EA_POSITION = 0;
status.Bits.EA_SLIP_STALL = 0;
Expand Down Expand Up @@ -708,7 +718,7 @@ PM304Config(int card, /* card being configured */
const char *port, /* asyn port name */
int n_axes, /* Number of axes */
int home_modes, /* Combined home modes of all axes */
int reset_before_move) /* Reset the McLennan before every move */
int reset_before_move) /* Reset (RS) the McLennan before every move */
{
struct PM304controller *cntrl;

Expand Down
13 changes: 13 additions & 0 deletions motorApp/MclennanSrc/drvPM304.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,22 @@ struct PM304controller
char datum_mode[PM304_MAX_CHANNELS][9]; /* PM600: datum mode as per DM command */
char abort_mode[PM304_MAX_CHANNELS][9]; /* PM600: abort mode as per AM command */
int velo[PM304_MAX_CHANNELS]; /* last set velocity, used in homing to set creep speed */
int datum[PM304_MAX_CHANNELS]; /* state of datum signal */
};

RTN_STATUS PM304Setup(int, int);
RTN_STATUS PM304Config(int, const char *, int, int, int);

enum HomeModes {
HOME_MODE_BUILTIN=0, HOME_MODE_CONST_VELOCITY_MOVE, HOME_MODE_REVERSE_HOME_AND_ZERO,
HOME_MODE_CONST_VELOCITY_MOVE_AND_ZERO, HOME_MODE_FORWARD_HOME_AND_ZERO,
HOME_MODE_FORWARD_LIMIT_REVERSE_HOME_AND_ZERO, HOME_MODE_REVERSE_LIMIT_FORWARD_HOME_AND_ZERO
};

static const char* home_mode_name[] = {
"HOME_MODE_BUILTIN", "HOME_MODE_CONST_VELOCITY_MOVE", "HOME_MODE_REVERSE_HOME_AND_ZERO",
"HOME_MODE_CONST_VELOCITY_MOVE_AND_ZERO", "HOME_MODE_FORWARD_HOME_AND_ZERO",
"HOME_MODE_FORWARD_LIMIT_REVERSE_HOME_AND_ZERO", "HOME_MODE_REVERSE_LIMIT_FORWARD_HOME_AND_ZERO"
};

#endif /* INCdrvPM304h */

0 comments on commit 407a34f

Please sign in to comment.