@ -31,13 +31,63 @@ void StepMotorCtrlScriptCmderModule::initialize(CmdScheduler* cmdScheduler) {
ZASSERT ( m_cmdScheduler ! = nullptr ) ;
regcmd ( ) ;
}
I_StepMotorCtrlModule * StepMotorCtrlScriptCmderModule : : findXYRobot ( int id ) {
int32_t StepMotorCtrlScriptCmderModule : : findmodule ( int id , I_StepMotorCtrlModule * * module ) {
auto it = moduler . find ( id ) ;
if ( it = = moduler . end ( ) ) {
return nullptr ;
return err : : kce_no_such_module ;
}
return it - > second ;
* module = it - > second ;
return 0 ;
}
# define GET_BIT(x, n) ((x >> n) & 0x01)
static void cmd_dump_ack ( I_StepMotorCtrlModule : : base_param_t & ack ) {
ZLOGI ( TAG , " base_param: " ) ;
ZLOGI ( TAG , " x_shaft: %d " , ack . x_shaft ) ;
ZLOGI ( TAG , " distance_scale: %d " , ack . distance_scale ) ;
ZLOGI ( TAG , " ihold: %d " , ack . ihold ) ;
ZLOGI ( TAG , " irun: %d " , ack . irun ) ;
ZLOGI ( TAG , " iholddelay: %d " , ack . iholddelay ) ;
ZLOGI ( TAG , " acc: %d " , ack . acc ) ;
ZLOGI ( TAG , " dec: %d " , ack . dec ) ;
ZLOGI ( TAG , " maxspeed: %d " , ack . maxspeed ) ;
ZLOGI ( TAG , " min_x: %d " , ack . min_x ) ;
ZLOGI ( TAG , " max_x: %d " , ack . max_x ) ;
ZLOGI ( TAG , " shift_x: %d " , ack . shift_x ) ;
ZLOGI ( TAG , " run_to_zero_move_to_zero_max_d: %d " , ack . run_to_zero_move_to_zero_max_d ) ;
ZLOGI ( TAG , " run_to_zero_leave_from_zero_max_d: %d " , ack . run_to_zero_leave_from_zero_max_d ) ;
ZLOGI ( TAG , " run_to_zero_speed: %d " , ack . run_to_zero_speed ) ;
ZLOGI ( TAG , " run_to_zero_dec: %d " , ack . run_to_zero_dec ) ;
}
static void cmd_dump_ack ( I_StepMotorCtrlModule : : logic_point_t & ack ) {
ZLOGI ( TAG , " logic_point: " ) ;
ZLOGI ( TAG , " index: %d " , ack . index ) ;
ZLOGI ( TAG , " acc: %d " , ack . acc ) ;
ZLOGI ( TAG , " dec: %d " , ack . dec ) ;
ZLOGI ( TAG , " velocity: %d " , ack . velocity ) ;
ZLOGI ( TAG , " x: %d " , ack . x ) ;
}
static void cmd_dump_ack ( I_StepMotorCtrlModule : : status_t & ack ) {
ZLOGI ( TAG , " status: " ) ;
ZLOGI ( TAG , " status: :%d " , ack . status ) ;
ZLOGI ( TAG , " io_state :%d,%d,%d,%d,%d,%d,%d,%d " , GET_BIT ( ack . io_state , 0 ) , GET_BIT ( ack . io_state , 1 ) , GET_BIT ( ack . io_state , 2 ) , GET_BIT ( ack . io_state , 3 ) , GET_BIT ( ack . io_state , 4 ) , GET_BIT ( ack . io_state , 5 ) , GET_BIT ( ack . io_state , 6 ) , GET_BIT ( ack . io_state , 7 ) ) ;
ZLOGI ( TAG , " x: :%d " , ack . x ) ;
}
static void cmd_dump_ack ( I_StepMotorCtrlModule : : detailed_status_t & ack ) {
ZLOGI ( TAG , " detailed_status: " ) ;
ZLOGI ( TAG , " status: %d " , ack . status ) ;
ZLOGI ( TAG , " io_state :%d,%d,%d,%d,%d,%d,%d,%d " , GET_BIT ( ack . io_state , 0 ) , GET_BIT ( ack . io_state , 1 ) , GET_BIT ( ack . io_state , 2 ) , GET_BIT ( ack . io_state , 3 ) , GET_BIT ( ack . io_state , 4 ) , GET_BIT ( ack . io_state , 5 ) , GET_BIT ( ack . io_state , 6 ) , GET_BIT ( ack . io_state , 7 ) ) ;
ZLOGI ( TAG , " x: %d " , ack . x ) ;
ZLOGI ( TAG , " last_exec_status: %d " , ack . last_exec_status ) ;
}
static void cmd_dump_ack ( I_StepMotorCtrlModule : : version_t & ack ) {
ZLOGI ( TAG , " version: " ) ;
ZLOGI ( TAG , " version: %d " , ack . version ) ;
}
static bool streq ( const char * a , const char * b ) { return strcmp ( a , b ) = = 0 ; }
@ -50,317 +100,127 @@ void StepMotorCtrlScriptCmderModule::regmodule(int id, I_StepMotorCtrlModule* ro
void StepMotorCtrlScriptCmderModule : : regcmd ( ) { //
ZASSERT ( m_cmdScheduler ! = nullptr ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_is_busy " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
bool ack = module - > isbusy ( ) ;
ZLOGI ( TAG , " is busy:%d " , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_is_busy " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
ZLOGI ( TAG , " is busy:%d " , module - > isbusy ( ) ) ;
return ( int32_t ) 0 ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_get_last_exec_status " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > get_last_exec_status ( ) ;
ZLOGI ( TAG , " last exec status:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_get_last_exec_status " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
ZLOGI ( TAG , " last exec status:%s(%d) " , err : : error2str ( module - > get_last_exec_status ( ) ) , module - > get_last_exec_status ( ) ) ;
return ( int32_t ) 0 ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t x = atoi ( argv [ 2 ] ) ;
int32_t speed = 0 ;
if ( argc > = 4 ) {
int32_t speed = atoi ( argv [ 3 ] ) ;
}
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > move_to ( x , speed , [ ] ( int32_t status ) { ZLOGI ( TAG , " move to exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
ZLOGI ( TAG , " move to:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to " , " (id,x,speed) " , 3 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( move_to , con - > getInt ( 1 ) , con - > getInt ( 2 ) , //
[ this ] ( int32_t status ) { ZLOGI ( TAG , " move to exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_by " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t dx = atoi ( argv [ 2 ] ) ;
int32_t speed = 0 ;
if ( argc > = 4 ) {
int32_t speed = atoi ( argv [ 3 ] ) ;
}
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > move_by ( dx , speed , [ ] ( int32_t status ) { ZLOGI ( TAG , " move by exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
ZLOGI ( TAG , " move by:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_by " , " (id,dx,speed) " , 3 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( move_by , con - > getInt ( 1 ) , con - > getInt ( 2 ) , //
[ this ] ( int32_t status ) { ZLOGI ( TAG , " move by exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to_zero " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > move_to_zero ( [ ] ( int32_t status ) { ZLOGI ( TAG , " move to zero exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
ZLOGI ( TAG , " move to zero:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to_zero " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( move_to_zero , [ this ] ( int32_t status ) { ZLOGI ( TAG , " move to zero exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to_zero_with_calibrate " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t x = atoi ( argv [ 2 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > move_to_zero_with_calibrate ( x , [ ] ( int32_t status ) { ZLOGI ( TAG , " move to zero with calibrate exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
ZLOGI ( TAG , " move to zero with calibrate:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to_zero_with_calibrate " , " (id,x) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( move_to_zero_with_calibrate , con - > getInt ( 1 ) , //
[ this ] ( int32_t status ) { ZLOGI ( TAG , " move to zero with calibrate exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_rotate " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t speed = atoi ( argv [ 2 ] ) ;
int32_t lastforms = 0 ;
if ( argc > = 4 ) {
int32_t lastforms = atoi ( argv [ 3 ] ) ;
}
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > rotate ( speed , lastforms , [ ] ( int32_t status ) { ZLOGI ( TAG , " rotate exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
ZLOGI ( TAG , " rotate:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_rotate " , " (id,speed,lastforms) " , 3 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( rotate , con - > getInt ( 1 ) , con - > getInt ( 2 ) , //
[ this ] ( int32_t status ) { ZLOGI ( TAG , " rotate exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_stop " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
uint8_t stopType = atoi ( argv [ 2 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > stop ( stopType ) ;
ZLOGI ( TAG , " stop:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_stop " , " (id,stop_type) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( stop , con - > getInt ( 1 ) ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_force_change_current_pos " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t x = atoi ( argv [ 2 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > force_change_current_pos ( x ) ;
ZLOGI ( TAG , " force change current pos:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_force_change_current_pos " , " (id,x) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( force_change_current_pos , con - > getInt ( 1 ) ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to_logic_point " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t logic_point_id = atoi ( argv [ 2 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > move_to_logic_point ( logic_point_id , [ ] ( int32_t status ) { ZLOGI ( TAG , " move to logic point exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
ZLOGI ( TAG , " move to logic point:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_move_to_logic_point " , " (id,logic_point_id) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( move_to_logic_point , con - > getInt ( 1 ) , //
[ this ] ( int32_t status ) { ZLOGI ( TAG , " move to logic point exec end status:%s(%d) " , err : : error2str ( status ) , status ) ; } ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_set_logic_point " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 6 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t logic_point_id = atoi ( argv [ 2 ] ) ;
int32_t x = atoi ( argv [ 3 ] ) ;
int32_t vel = atoi ( argv [ 4 ] ) ;
int32_t acc = atoi ( argv [ 5 ] ) ;
int32_t dec = atoi ( argv [ 6 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > set_logic_point ( logic_point_id , x , vel , acc , dec ) ;
ZLOGI ( TAG , " set logic point:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_set_logic_point " , " (id,logic_point_id,x,vel,acc,dec) " , 6 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( set_logic_point , con - > getInt ( 1 ) , con - > getInt ( 2 ) , con - > getInt ( 3 ) , con - > getInt ( 4 ) , con - > getInt ( 5 ) ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_set_logic_point_simplify " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t logic_point_id = atoi ( argv [ 2 ] ) ;
int32_t x = 0 ;
int32_t vel = 0 ;
int32_t acc = 0 ;
int32_t dec = 0 ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
x = module - > read_pos ( ) ;
int32_t ack = module - > set_logic_point ( logic_point_id , x , vel , acc , dec ) ;
ZLOGI ( TAG , " set logic point:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_set_logic_point_simplify " , " (id,logic_point_id) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( set_logic_point , con - > getInt ( 1 ) , module - > read_pos ( ) , 0 , 0 , 0 ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_get_logic_point " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int32_t logic_point_id = atoi ( argv [ 2 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
I_StepMotorCtrlModule : : logic_point_t logic_point ;
int32_t ack = module - > get_logic_point ( logic_point_id , logic_point ) ;
if ( ack ! = 0 ) {
ZLOGI ( TAG , " get logic point:%s(%d) " , err : : error2str ( ack ) , ack ) ;
return ;
}
ZLOGI ( TAG , " logic_point_id :%d " , logic_point . index ) ;
ZLOGI ( TAG , " logic_point.x :%d " , logic_point . x ) ;
ZLOGI ( TAG , " logic_point.vel :%d " , logic_point . velocity ) ;
ZLOGI ( TAG , " logic_point.acc :%d " , logic_point . acc ) ;
ZLOGI ( TAG , " logic_point.dec :%d " , logic_point . dec ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_get_logic_point " , " (id,logic_point_id) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
I_StepMotorCtrlModule : : logic_point_t ack ;
IMPL_READ_STATE ( get_logic_point , con - > getInt ( 1 ) , ack ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_flush " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > flush ( ) ;
ZLOGI ( TAG , " flush:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_get_base_param " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
I_StepMotorCtrlModule : : base_param_t ack ;
IMPL_READ_STATE ( get_base_param , ack ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_enable " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 2 ) ;
int id = atoi ( argv [ 1 ] ) ;
int enable = atoi ( argv [ 2 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > enable ( enable ) ;
ZLOGI ( TAG , " flush:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_flush " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( flush ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_factory_reset " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
int32_t ack = module - > factory_reset ( ) ;
ZLOGI ( TAG , " factory reset:%s(%d) " , err : : error2str ( ack ) , ack ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_enable " , " (id,en) " , 2 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( enable , con - > getBool ( 1 ) ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_read_version " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
I_StepMotorCtrlModule : : version_t version ;
int32_t ack = module - > read_version ( version ) ;
if ( ack ! = 0 ) {
ZLOGI ( TAG , " read version:%s(%d) " , err : : error2str ( ack ) , ack ) ;
return ;
}
ZLOGI ( TAG , " version.version:%d " , version . version ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_factory_reset " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
IMPL_CMD ( factory_reset ) ;
} ) ;
# define GET_BIT(x, n) ((x >> n) & 0x01)
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_read_status " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
I_StepMotorCtrlModule : : status_t status ;
int32_t ack = module - > read_status ( status ) ;
if ( ack ! = 0 ) {
ZLOGI ( TAG , " read status:%s(%d) " , err : : error2str ( ack ) , ack ) ;
return ;
}
ZLOGI ( TAG , " status.status :%d " , status . status ) ;
ZLOGI ( TAG , " status.io_state :%d,%d,%d,%d,%d,%d,%d,%d " , GET_BIT ( status . io_state , 0 ) , GET_BIT ( status . io_state , 1 ) , GET_BIT ( status . io_state , 2 ) , GET_BIT ( status . io_state , 3 ) , GET_BIT ( status . io_state , 4 ) , GET_BIT ( status . io_state , 5 ) , GET_BIT ( status . io_state , 6 ) , GET_BIT ( status . io_state , 7 ) ) ;
ZLOGI ( TAG , " status.x :%d " , status . x ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_read_version " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
I_StepMotorCtrlModule : : version_t ack ;
IMPL_READ_STATE ( read_version , ack ) ;
} ) ;
// virtual int32_t read_detailed_status(detailed_status_t& debug_info) = 0;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_read_detailed_status " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
I_StepMotorCtrlModule : : detailed_status_t status ;
int32_t ack = module - > read_detailed_status ( status ) ;
if ( ack ! = 0 ) {
ZLOGI ( TAG , " read status:%s(%d) " , err : : error2str ( ack ) , ack ) ;
return ;
}
ZLOGI ( TAG , " status.status :%d " , status . status ) ;
ZLOGI ( TAG , " status.io_state :%d,%d,%d,%d,%d,%d,%d,%d " , GET_BIT ( status . io_state , 0 ) , GET_BIT ( status . io_state , 1 ) , GET_BIT ( status . io_state , 2 ) , GET_BIT ( status . io_state , 3 ) , GET_BIT ( status . io_state , 4 ) , GET_BIT ( status . io_state , 5 ) , GET_BIT ( status . io_state , 6 ) , GET_BIT ( status . io_state , 7 ) ) ;
ZLOGI ( TAG , " status.x :%d " , status . x ) ;
ZLOGI ( TAG , " status.last_exec_status :%d " , status . last_exec_status ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_read_status " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
I_StepMotorCtrlModule : : status_t ack ;
IMPL_READ_STATE ( read_status , ack ) ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_set_base_param " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_MIN_ARGC ( 3 ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_read_detailed_status " , " (id) " , 1 , [ this ] ( CmdScheduler : : Context * con ) {
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
I_StepMotorCtrlModule : : detailed_status_t ack ;
IMPL_READ_STATE ( read_detailed_status , ack ) ;
} ) ;
int id = atoi ( argv [ 1 ] ) ;
const char * paramName = argv [ 2 ] ;
int32_t value = atoi ( argv [ 3 ] ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_set_base_param " , " (id,paramName,val) " , 3 , [ this ] ( CmdScheduler : : Context * con ) {
const char * paramName = con - > getString ( 2 ) ;
int32_t value = con - > getInt ( 3 ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
DO_CMD ( findmodule ( con - > getInt ( 0 ) , & module ) ) ;
I_StepMotorCtrlModule : : base_param_t param ;
int32_t ack = module - > get_base_param ( param ) ;
if ( ack ! = 0 ) {
ZLOGE ( TAG , " get_base_param failed:%d " , ack ) ;
return ;
}
DO_CMD ( module - > get_base_param ( param ) ) ;
if ( streq ( paramName , " x_shaft " ) ) {
param . x_shaft = value ;
} else if ( streq ( paramName , " distance_scale " ) ) {
@ -393,46 +253,9 @@ void StepMotorCtrlScriptCmderModule::regcmd() { //
param . run_to_zero_dec = value ;
} else {
ZLOGE ( TAG , " invalid param name:%s " , paramName ) ;
return ;
}
ack = module - > set_base_param ( param ) ;
if ( ack ! = 0 ) {
ZLOGE ( TAG , " set_base_param failed:%s(%d) " , err : : error2str ( ack ) , ack ) ;
return ;
return ( int32_t ) err : : kce_param_out_of_range ;
}
ZLOGI ( TAG , " set_base_param ok " ) ;
return ;
} ) ;
m_cmdScheduler - > registerCmd ( " step_motor_ctrl_get_base_param " , [ this ] ( int argc , char * * argv , CmdScheduler : : CmdProcessContext * context ) {
CHECK_ARGC ( 1 ) ;
int id = atoi ( argv [ 1 ] ) ;
I_StepMotorCtrlModule * module = findXYRobot ( id ) ;
SCRIPT_CMDER_CHECK ( module ! = nullptr ) ;
I_StepMotorCtrlModule : : base_param_t param ;
int32_t ack = module - > get_base_param ( param ) ;
if ( ack ! = 0 ) {
ZLOGE ( TAG , " get_base_param failed:%d " , ack ) ;
return ;
}
ZLOGI ( TAG , " param.x_shaft :%d " , param . x_shaft ) ;
ZLOGI ( TAG , " param.distance_scale :%d " , param . distance_scale ) ;
ZLOGI ( TAG , " param.ihold :%d " , param . ihold ) ;
ZLOGI ( TAG , " param.irun :%d " , param . irun ) ;
ZLOGI ( TAG , " param.iholddelay :%d " , param . iholddelay ) ;
ZLOGI ( TAG , " param.acc :%d " , param . acc ) ;
ZLOGI ( TAG , " param.dec :%d " , param . dec ) ;
ZLOGI ( TAG , " param.maxspeed :%d " , param . maxspeed ) ;
ZLOGI ( TAG , " param.min_x :%d " , param . min_x ) ;
ZLOGI ( TAG , " param.max_x :%d " , param . max_x ) ;
ZLOGI ( TAG , " param.shift_x :%d " , param . shift_x ) ;
ZLOGI ( TAG , " param.run_to_zero_move_to_zero_max_d:%d " , param . run_to_zero_move_to_zero_max_d ) ;
ZLOGI ( TAG , " param.run_to_zero_leave_from_zero_max_d:%d " , param . run_to_zero_leave_from_zero_max_d ) ;
ZLOGI ( TAG , " param.run_to_zero_speed :%d " , param . run_to_zero_speed ) ;
ZLOGI ( TAG , " param.run_to_zero_dec :%d " , param . run_to_zero_dec ) ;
DO_CMD ( module - > set_base_param ( param ) ) ;
return ( int32_t ) 0 ;
} ) ;
}