mirror of
https://github.com/eddyem/pusirobot.git
synced 2025-12-06 02:25:10 +03:00
add quiet option, fix something
This commit is contained in:
parent
240b5f8677
commit
fe0fe62cad
@ -1,7 +1,7 @@
|
||||
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]
|
||||
@ -9,16 +9,28 @@ Usage: steppermove [args]
|
||||
Where args are:
|
||||
|
||||
-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)
|
||||
-R, --readvals read values of used parameters
|
||||
-S, --stop stop motor
|
||||
-a, --abs=arg move to absolute position (steps)
|
||||
-c, --clearerr clear errors
|
||||
-d, --device=arg serial device name (default: /dev/ttyUSB0)
|
||||
-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
|
||||
-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)
|
||||
-s, --canspd=arg CAN bus speed (default: DEFAULT_SPEED)
|
||||
-t, --serialspd=arg serial (tty) device speed (default: DEFAULT_SPEED)
|
||||
-s, --canspd=arg CAN bus speed
|
||||
-t, --serialspd=arg serial (tty) device speed (default: 115200)
|
||||
-u, --microsteps=arg microstepping (0..256)
|
||||
-w, --wait wait while motor is busy
|
||||
|
||||
|
||||
## Some usefull information
|
||||
|
||||
Factory settings of pusirobot drivers: 125kBaud, nodeID=5
|
||||
|
||||
16
commandline/cfg/Fmove
Executable file
16
commandline/cfg/Fmove
Executable 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
|
||||
|
||||
6
commandline/cfg/OfflinePrgmng.cfg
Normal file
6
commandline/cfg/OfflinePrgmng.cfg
Normal file
@ -0,0 +1,6 @@
|
||||
# Turn off offline programming
|
||||
0x6018, 1, 0
|
||||
0x6018, 2, 0
|
||||
# Save parameters
|
||||
0x2007, 0, 2
|
||||
|
||||
@ -60,8 +60,8 @@ static myoption cmdlnopts[] = {
|
||||
// common options
|
||||
{"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 ")")},
|
||||
{"canspd", NEED_ARG, NULL, 's', arg_int, APTR(&G.canspeed), _("CAN bus speed (default: " STR(DEFAULT_SPEED) ")")},
|
||||
{"serialspd",NEED_ARG, NULL, 't', arg_int, APTR(&G.serialspeed),_("serial (tty) device 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_SER_SPEED) ")")},
|
||||
{"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 ")")},
|
||||
{"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")},
|
||||
{"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")},
|
||||
{"quick", NO_ARGS, NULL, 'q', arg_int, APTR(&G.quick), _("directly send command without getting status")},
|
||||
end_option
|
||||
};
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ typedef struct{
|
||||
int showpars; // show values of some parameters
|
||||
int enableESW; // send signal to enable end-switches
|
||||
int wait; // wait while device is busy
|
||||
int quick; // directly send command without getting status
|
||||
} glob_pars;
|
||||
|
||||
|
||||
|
||||
@ -117,6 +117,9 @@ DICENTRY(GPIOCONF, 0x6011, 2, 4, 0, "GPIO configuration")
|
||||
DICENTRY(GPIOVAL, 0x6012, 0, 2, 0, "GPIO value")
|
||||
// stall parameters
|
||||
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
|
||||
DICENTRY(STALLSET, 0x601B, 0, 1, 0, "stall set (open loop)")
|
||||
// absolute displacement
|
||||
|
||||
@ -132,8 +132,8 @@ static inline void showAllPars(){
|
||||
entry->index, entry->subindex, entry->name);
|
||||
continue;
|
||||
}
|
||||
printf("# %s\n0x%04X, %d, %ld\n", entry->name, entry->index,
|
||||
entry->subindex, val);
|
||||
printf("# %s\n0x%04X, %d, %ld (0x%lX)\n", entry->name, entry->index,
|
||||
entry->subindex, val, val);
|
||||
fflush(stdout);
|
||||
}
|
||||
printf("\n\n");
|
||||
@ -196,15 +196,13 @@ int main(int argc, char *argv[]){
|
||||
setserialspeed(GP->serialspeed);
|
||||
if(canbus_open(GP->device)){
|
||||
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)){
|
||||
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
|
||||
int64_t i64;
|
||||
ID = GP->NodeID;
|
||||
@ -215,58 +213,63 @@ int main(int argc, char *argv[]){
|
||||
//#define Mesg(...) green(__VA_ARGS__)
|
||||
//double d0 = dtime();
|
||||
|
||||
getSDOe(ERRSTATE, chkerr, "Can't get error status");
|
||||
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);
|
||||
}
|
||||
|
||||
// get mircostepping (need this to properly calculate current position and move
|
||||
getSDOe(MICROSTEPS, setusteps, "Can't get microstepping");
|
||||
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)))
|
||||
green("CURPOS=%d\n", (int)i64/microstepping);
|
||||
else WARNX("Can't read current position");
|
||||
Mesg("CURPOS: %g\n", dtime() - d0);
|
||||
|
||||
if(GP->showpars){
|
||||
showAllPars();
|
||||
Mesg("showAllPars: %g\n", dtime() - d0);
|
||||
}
|
||||
|
||||
// get limit switches values
|
||||
getSDOe(GPIOVAL, gpioval, "Can't read GPIO values");
|
||||
Mesg("GPIOVAL: %g\n", dtime() - d0);
|
||||
|
||||
if(GP->disable){
|
||||
if(SDO_write(&ENABLE, ID, 0)) ERRX("Can't disable motor");
|
||||
Mesg("DISABLE: %g\n", dtime() - d0);
|
||||
}
|
||||
|
||||
// get motor power status
|
||||
if(INT64_MIN != (i64 = SDO_read(&ENABLE, ID))){
|
||||
if(i64) green("ENABLE=1\n");
|
||||
else red("ENABLE=0\n");
|
||||
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();
|
||||
|
||||
// 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){
|
||||
green("Try to parse %s and send SDOs to device\n", GP->parsefile);
|
||||
parse_data_file(GP->parsefile, GP->NodeID);
|
||||
Mesg("parse_data_file: %g\n", dtime() - d0);
|
||||
}
|
||||
|
||||
// enable limit switches
|
||||
if(GP->enableESW){
|
||||
if(SDO_write(&EXTENABLE, ID, 3)){
|
||||
WARNX("Error when trying to enable limit switches");
|
||||
@ -274,10 +277,7 @@ int main(int argc, char *argv[]){
|
||||
}
|
||||
Mesg("EXTENABLE: %g\n", dtime() - d0);
|
||||
}
|
||||
|
||||
getSDOe(MAXSPEED, setmaxspd, "Can't read max speed");
|
||||
Mesg("MAXSPEED: %g\n", dtime() - d0);
|
||||
|
||||
// move to absolute position
|
||||
if(GP->absmove != INT_MIN){
|
||||
if(devstat == BUSY_STATE) ERRX("Can't move in BUSY state");
|
||||
SDO_write(&ENABLE, ID, 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user