add quiet option, fix something

This commit is contained in:
Edward Emelianov 2020-10-01 12:41:57 +03:00
parent 240b5f8677
commit fe0fe62cad
8 changed files with 90 additions and 51 deletions

View File

@ -1,7 +1,7 @@
Command line motor management Command line motor management
============================= =============================
CAN controller: my CAN-USB sniffer Works with [my CAN-USB sniffer](https://github.com/eddyem/stm32samples/tree/master/F0-nolib/usbcan).
Usage: steppermove [args] Usage: steppermove [args]
@ -9,16 +9,28 @@ Usage: steppermove [args]
Where args are: Where args are:
-0, --zeropos set current position to zero -0, --zeropos set current position to zero
-D, --disable disable motor
-E, --enablesw enable end-switches 1 and 2
-I, --nodeid=arg node ID (1..127)
-P, --pidfile=arg pidfile (default: /tmp/steppersmng.pid) -P, --pidfile=arg pidfile (default: /tmp/steppersmng.pid)
-R, --readvals read values of used parameters
-S, --stop stop motor -S, --stop stop motor
-a, --abs=arg move to absolute position (steps) -a, --abs=arg move to absolute position (steps)
-c, --clearerr clear errors -c, --clearerr clear errors
-d, --device=arg serial device name (default: /dev/ttyUSB0) -d, --device=arg serial device name (default: /dev/ttyUSB0)
-h, --help show this help -h, --help show this help
-i, --nodeid=arg node ID (1..127) -k, --check=arg check SDO data file
-l, --logfile=arg file to save logs -l, --logfile=arg file to save logs
-m, --maxspd=arg maximal motor speed (steps per second) -m, --maxspd=arg maximal motor speed (steps per second)
-p, --parse=arg file with SDO data to send to device
-q, --quick directly send command without getting status
-r, --rel=arg move to relative position (steps) -r, --rel=arg move to relative position (steps)
-s, --canspd=arg CAN bus speed (default: DEFAULT_SPEED) -s, --canspd=arg CAN bus speed
-t, --serialspd=arg serial (tty) device speed (default: DEFAULT_SPEED) -t, --serialspd=arg serial (tty) device speed (default: 115200)
-u, --microsteps=arg microstepping (0..256) -u, --microsteps=arg microstepping (0..256)
-w, --wait wait while motor is busy
## Some usefull information
Factory settings of pusirobot drivers: 125kBaud, nodeID=5

View File

@ -147,7 +147,7 @@ int canbus_open(const char *devname){
int canbus_setspeed(int speed){ int canbus_setspeed(int speed){
if(speed == 0) return 0; // default - not change if(speed == 0) return 0; // default - not change
char buff[BUFLEN]; char buff[BUFLEN];
if(speed<10 || speed>3000){ if(speed < 10 || speed > 3000){
WARNX("Wrong CAN bus speed value: %d", speed); WARNX("Wrong CAN bus speed value: %d", speed);
return 1; return 1;
} }

16
commandline/cfg/Fmove Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <steps>"
exit 1
fi
STEPS=$1
NEGSTEPS=$((-$1))
echo "Move focus to $STEPS steps"
./steppermove -qI1 -r $NEGSTEPS
./steppermove -qI2 -r $STEPS
./steppermove -qI3 -r $STEPS

View File

@ -0,0 +1,6 @@
# Turn off offline programming
0x6018, 1, 0
0x6018, 2, 0
# Save parameters
0x2007, 0, 2

View File

@ -60,8 +60,8 @@ static myoption cmdlnopts[] = {
// common options // common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")}, {"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"device", NEED_ARG, NULL, 'd', arg_string, APTR(&G.device), _("serial device name (default: " DEFAULT_PORTDEV ")")}, {"device", NEED_ARG, NULL, 'd', arg_string, APTR(&G.device), _("serial device name (default: " DEFAULT_PORTDEV ")")},
{"canspd", NEED_ARG, NULL, 's', arg_int, APTR(&G.canspeed), _("CAN bus speed (default: " STR(DEFAULT_SPEED) ")")}, {"canspd", NEED_ARG, NULL, 's', arg_int, APTR(&G.canspeed), _("CAN bus speed")},
{"serialspd",NEED_ARG, NULL, 't', arg_int, APTR(&G.serialspeed),_("serial (tty) device speed (default: " STR(DEFAULT_SPEED) ")")}, {"serialspd",NEED_ARG, NULL, 't', arg_int, APTR(&G.serialspeed),_("serial (tty) device speed (default: " STR(DEFAULT_SER_SPEED) ")")},
{"logfile", NEED_ARG, NULL, 'l', arg_string, APTR(&G.logfile), _("file to save logs")}, {"logfile", NEED_ARG, NULL, 'l', arg_string, APTR(&G.logfile), _("file to save logs")},
{"pidfile", NEED_ARG, NULL, 'P', arg_string, APTR(&G.pidfile), _("pidfile (default: " DEFAULT_PIDFILE ")")}, {"pidfile", NEED_ARG, NULL, 'P', arg_string, APTR(&G.pidfile), _("pidfile (default: " DEFAULT_PIDFILE ")")},
{"nodeid", NEED_ARG, NULL, 'I', arg_int, APTR(&G.NodeID), _("node ID (1..127)")}, {"nodeid", NEED_ARG, NULL, 'I', arg_int, APTR(&G.NodeID), _("node ID (1..127)")},
@ -78,6 +78,7 @@ static myoption cmdlnopts[] = {
{"readvals",NO_ARGS, NULL, 'R', arg_int, APTR(&G.showpars), _("read values of used parameters")}, {"readvals",NO_ARGS, NULL, 'R', arg_int, APTR(&G.showpars), _("read values of used parameters")},
{"enablesw",NO_ARGS, NULL, 'E', arg_int, APTR(&G.enableESW), _("enable end-switches 1 and 2")}, {"enablesw",NO_ARGS, NULL, 'E', arg_int, APTR(&G.enableESW), _("enable end-switches 1 and 2")},
{"wait", NO_ARGS, NULL, 'w', arg_int, APTR(&G.wait), _("wait while motor is busy")}, {"wait", NO_ARGS, NULL, 'w', arg_int, APTR(&G.wait), _("wait while motor is busy")},
{"quick", NO_ARGS, NULL, 'q', arg_int, APTR(&G.quick), _("directly send command without getting status")},
end_option end_option
}; };

View File

@ -51,6 +51,7 @@ typedef struct{
int showpars; // show values of some parameters int showpars; // show values of some parameters
int enableESW; // send signal to enable end-switches int enableESW; // send signal to enable end-switches
int wait; // wait while device is busy int wait; // wait while device is busy
int quick; // directly send command without getting status
} glob_pars; } glob_pars;

View File

@ -117,6 +117,9 @@ DICENTRY(GPIOCONF, 0x6011, 2, 4, 0, "GPIO configuration")
DICENTRY(GPIOVAL, 0x6012, 0, 2, 0, "GPIO value") DICENTRY(GPIOVAL, 0x6012, 0, 2, 0, "GPIO value")
// stall parameters // stall parameters
DICENTRY(STALLPARS, 0x6017, 0, 2, 0, "stall parameters (open loop)") DICENTRY(STALLPARS, 0x6017, 0, 2, 0, "stall parameters (open loop)")
// offline operation
DICENTRY(OFFLNMBR, 0x6018, 1, 1, 0, "Number of offline programming command")
DICENTRY(OFFLENBL, 0x6018, 2, 1, 0, "Offline automatic operation enable")
// stall set // stall set
DICENTRY(STALLSET, 0x601B, 0, 1, 0, "stall set (open loop)") DICENTRY(STALLSET, 0x601B, 0, 1, 0, "stall set (open loop)")
// absolute displacement // absolute displacement

View File

@ -132,8 +132,8 @@ static inline void showAllPars(){
entry->index, entry->subindex, entry->name); entry->index, entry->subindex, entry->name);
continue; continue;
} }
printf("# %s\n0x%04X, %d, %ld\n", entry->name, entry->index, printf("# %s\n0x%04X, %d, %ld (0x%lX)\n", entry->name, entry->index,
entry->subindex, val); entry->subindex, val, val);
fflush(stdout); fflush(stdout);
} }
printf("\n\n"); printf("\n\n");
@ -196,15 +196,13 @@ int main(int argc, char *argv[]){
setserialspeed(GP->serialspeed); setserialspeed(GP->serialspeed);
if(canbus_open(GP->device)){ if(canbus_open(GP->device)){
putlog("Can't open %s @ speed %d. Exit.", GP->device, GP->serialspeed); putlog("Can't open %s @ speed %d. Exit.", GP->device, GP->serialspeed);
signals(1); ERRX("Can't open %s @ speed %d. Exit.", GP->device, GP->serialspeed);
} }
if(canbus_setspeed(GP->canspeed)){ if(canbus_setspeed(GP->canspeed)){
putlog("Can't set CAN speed %d. Exit.", GP->canspeed); putlog("Can't set CAN speed %d. Exit.", GP->canspeed);
signals(2); ERRX("Can't set CAN speed %d. Exit.", GP->canspeed);
} }
DBG("here");
//setup_con();
// print current position and state // print current position and state
int64_t i64; int64_t i64;
ID = GP->NodeID; ID = GP->NodeID;
@ -215,58 +213,63 @@ int main(int argc, char *argv[]){
//#define Mesg(...) green(__VA_ARGS__) //#define Mesg(...) green(__VA_ARGS__)
//double d0 = dtime(); //double d0 = dtime();
getSDOe(ERRSTATE, chkerr, "Can't get error status"); // get mircostepping (need this to properly calculate current position and move
Mesg("ERRSTATE: %g\n", dtime() - d0);
if(GP->stop){
if(SDO_write(&STOP, ID, 1)) ERRX("Can't stop motor");
Mesg("STOP: %g\n", dtime() - d0);
}
getSDOe(DEVSTATUS, chkstat, "Can't get device status");
Mesg("DEVSTATUS: %g\n", dtime() - d0);
if(GP->zeropos){
if(SDO_write(&POSITION, ID, 0))
ERRX("Can't clear position counter");
Mesg("POSITION: %g\n", dtime() - d0);
}
getSDOe(MICROSTEPS, setusteps, "Can't get microstepping"); getSDOe(MICROSTEPS, setusteps, "Can't get microstepping");
Mesg("MICROSTEPS: %g\n", dtime() - d0); Mesg("MICROSTEPS: %g\n", dtime() - d0);
if(!GP->quick){
// check error status
getSDOe(ERRSTATE, chkerr, "Can't get error status");
Mesg("ERRSTATE: %g\n", dtime() - d0);
// get current position
if(INT64_MIN != (i64 = SDO_read(&POSITION, ID))) if(INT64_MIN != (i64 = SDO_read(&POSITION, ID)))
green("CURPOS=%d\n", (int)i64/microstepping); green("CURPOS=%d\n", (int)i64/microstepping);
else WARNX("Can't read current position"); else WARNX("Can't read current position");
Mesg("CURPOS: %g\n", dtime() - d0); Mesg("CURPOS: %g\n", dtime() - d0);
// get limit switches values
if(GP->showpars){
showAllPars();
Mesg("showAllPars: %g\n", dtime() - d0);
}
getSDOe(GPIOVAL, gpioval, "Can't read GPIO values"); getSDOe(GPIOVAL, gpioval, "Can't read GPIO values");
Mesg("GPIOVAL: %g\n", dtime() - d0); Mesg("GPIOVAL: %g\n", dtime() - d0);
// get motor power status
if(GP->disable){
if(SDO_write(&ENABLE, ID, 0)) ERRX("Can't disable motor");
Mesg("DISABLE: %g\n", dtime() - d0);
}
if(INT64_MIN != (i64 = SDO_read(&ENABLE, ID))){ if(INT64_MIN != (i64 = SDO_read(&ENABLE, ID))){
if(i64) green("ENABLE=1\n"); if(i64) green("ENABLE=1\n");
else red("ENABLE=0\n"); else red("ENABLE=0\n");
Mesg("Status: %g\n", dtime() - d0); Mesg("Status: %g\n", dtime() - d0);
} }
// get max speed
getSDOe(MAXSPEED, setmaxspd, "Can't read max speed");
Mesg("MAXSPEED: %g\n", dtime() - d0);
}
// check device status
getSDOe(DEVSTATUS, chkstat, "Can't get device status");
Mesg("DEVSTATUS: %g\n", dtime() - d0);
if(devstat == BUSY_STATE && GP->wait) wait_busy(); if(devstat == BUSY_STATE && GP->wait) wait_busy();
// stop motor
if(GP->stop){
if(SDO_write(&STOP, ID, 1)) ERRX("Can't stop motor");
Mesg("STOP: %g\n", dtime() - d0);
}
// turn off motor power
if(GP->disable){
if(SDO_write(&ENABLE, ID, 0)) ERRX("Can't disable motor");
Mesg("DISABLE: %g\n", dtime() - d0);
}
// zero position
if(GP->zeropos){
if(SDO_write(&POSITION, ID, 0))
ERRX("Can't clear position counter");
Mesg("POSITION: %g\n", dtime() - d0);
}
// show values of all known CanOpen parameters
if(GP->showpars){
showAllPars();
Mesg("showAllPars: %g\n", dtime() - d0);
}
// send values from external configuration file
if(GP->parsefile){ if(GP->parsefile){
green("Try to parse %s and send SDOs to device\n", GP->parsefile); green("Try to parse %s and send SDOs to device\n", GP->parsefile);
parse_data_file(GP->parsefile, GP->NodeID); parse_data_file(GP->parsefile, GP->NodeID);
Mesg("parse_data_file: %g\n", dtime() - d0); Mesg("parse_data_file: %g\n", dtime() - d0);
} }
// enable limit switches
if(GP->enableESW){ if(GP->enableESW){
if(SDO_write(&EXTENABLE, ID, 3)){ if(SDO_write(&EXTENABLE, ID, 3)){
WARNX("Error when trying to enable limit switches"); WARNX("Error when trying to enable limit switches");
@ -274,10 +277,7 @@ int main(int argc, char *argv[]){
} }
Mesg("EXTENABLE: %g\n", dtime() - d0); Mesg("EXTENABLE: %g\n", dtime() - d0);
} }
// move to absolute position
getSDOe(MAXSPEED, setmaxspd, "Can't read max speed");
Mesg("MAXSPEED: %g\n", dtime() - d0);
if(GP->absmove != INT_MIN){ if(GP->absmove != INT_MIN){
if(devstat == BUSY_STATE) ERRX("Can't move in BUSY state"); if(devstat == BUSY_STATE) ERRX("Can't move in BUSY state");
SDO_write(&ENABLE, ID, 1); SDO_write(&ENABLE, ID, 1);