Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdChainOut Class Referenceabstract

Dynamixel chain output command abstract base class. More...

#include <dynashell_cmd.h>

Inheritance diagram for DynaShellCmdChainOut:
DynaShellCmd DynaShellCmdCfgWriteServoMode DynaShellCmdMoveTo DynaShellCmdWriteGoalSpeed DynaShellCmdWriteTorqueEnable

Public Member Functions

 DynaShellCmdChainOut (bool bMasterOpOnly=false)
 Default constructor.
 
virtual ~DynaShellCmdChainOut ()
 Default destructor.
 
virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute 'write-like' command on servos. More...
 
virtual char * TabCompletion (DynaShell &shell, const char *sText, size_t uTextLen, int nState, const char *sContext)
 Command tab completion generator. More...
 
- Public Member Functions inherited from DynaShellCmd
 DynaShellCmd (int nArgCntMin=0, int nArgCntMax=0)
 Default constructor.
 
virtual ~DynaShellCmd ()
 Default destructor.
 
const char * GetCmdName ()
 Get dynamixel shell command name. More...
 
const char * GetCmdHelpBrief ()
 Get shell command name brief description. More...
 
virtual void PrintHelp (int indent=0, int width=80)
 Print command help with the description aligned at the given indentation. More...
 
int GetPublishedLevel () const
 
const char * GetPublishedName () const
 
int SetPublishedInfo (int nLevel, const char *sParent=NULL)
 
virtual bool ChkArgCnt (DynaShell &shell, int argc)
 Check that the argument count is within the class (min,max). More...
 
bool ChkArgCnt0 (DynaShell &shell, int argc)
 Check that the argument count is zero. More...
 
bool ChkArgCntEQ (DynaShell &shell, int argc, int eq)
 Check that the argument count is equal to the required. More...
 
bool ChkArgCntGE (DynaShell &shell, int argc, int min)
 Check argument count against minimum required. More...
 
bool ChkArgCntLE (DynaShell &shell, int argc, int max)
 Check argument count against maximum allowed. More...
 
bool ChkComm (DynaShell &shell)
 Check that Dynamixel communication exists and is open. More...
 
bool ChkChain (DynaShell &shell)
 Check that the servo chain exists. More...
 
bool ChkChainNotEmpty (DynaShell &shell)
 Check that the servo chain exists and is not empty. More...
 
bool ChkChainHasServo (DynaShell &shell, int nServoId)
 Check that the given servo is present in the chain. More...
 
bool ChkChainIsMasterServo (DynaShell &shell, int nServoId)
 Check that the given servo is a master. More...
 
bool ToInt (DynaShell &shell, const char *sArg, int *pVal)
 Convert command argument to integer. More...
 
bool ToUInt (DynaShell &shell, const char *sArg, uint_t *pVal)
 Convert command argument to unsigned integer. More...
 
bool ToDouble (DynaShell &shell, const char *sArg, double *pVal)
 Convert command argument to double. More...
 
bool ToBool (DynaShell &shell, const char *sArg, bool *pVal)
 Convert command argument to boolean. More...
 

Protected Member Functions

virtual void doExec (DynaShell &shell, ExecTup_T tup[], uint_t uCount)=0
 Derived class specific execution function. More...
 
virtual bool ArgToUInt (DynaShell &shell, const char *sArg, uint_t *pVal)
 Convert command argument into unsigned integer. More...
 
virtual bool ArgToInt (DynaShell &shell, const char *sArg, int *pVal)
 
- Protected Member Functions inherited from DynaShellCmd
virtual void PrintSynopses (int indent, int width)
 Print synsopses. More...
 
virtual void PrintBlock (int col, int indent, int width, const char *sText)
 Print a block of indented text of width. More...
 
virtual void PrintDelim (int width, const char cDelim)
 
char * eow (const char *s)
 Find end of word. More...
 

Protected Attributes

bool m_bMasterOpOnly
 is [not] a master-only supported operation
 
int m_nTabIter
 tab completion: servo id iterator
 
int m_nTabServoId
 tab completion: current servo id
 
bool m_bTabIncChain
 tab completion: [do not] include chain keyword
 
- Protected Attributes inherited from DynaShellCmd
const char * m_sCmdName
 command name
 
const char * m_sCmdHelpBrief
 command help brief
 
const char * m_sCmdHelpArgs
 command help arguments
 
const char * m_sCmdHelpDesc
 command help description
 
const int m_nArgCntMin
 minimum argument count
 
const int m_nArgCntMax
 maximum argument count (0 if not max)
 
int m_nPubLevel
 command's published level (depth)
 
char * m_sPubName
 command's published name
 

Detailed Description

Dynamixel chain output command abstract base class.

This class supports parsing a 2-tuple list of (master) servos as arguments to a derived command class executinng servo 'write-like' output operations. Output operations include write, move, and set.

Syntax:
* CMD args
* args ::=
*      'chain' value
*    | tuple_list
*  tuple_list ::=
*      tuple
*    | tuple_list tuple
*  tuple ::=
*      servo_id value
*  servo_id ::= INT
*  value ::= VAL_TO_UINT
* 

Definition at line 654 of file dynashell_cmd.h.

Member Function Documentation

virtual bool DynaShellCmdChainOut::ArgToUInt ( DynaShell shell,
const char *  sArg,
uint_t *  pVal 
)
inlineprotectedvirtual

Convert command argument into unsigned integer.

Parameters
shellDynamixel shell.
sArgString argument to convert.
[out]pValConverted argument.
Returns
Returns true on success, false otherwise.

Definition at line 703 of file dynashell_cmd.h.

References PublishShellCoreCommands(), PublishShellInterfaceCommands(), PublishShellServoCommands(), and PublishShellTrainCommands().

704  {
705  return ToUInt(shell, sArg, pVal);
706  }
bool ToUInt(DynaShell &shell, const char *sArg, uint_t *pVal)
Convert command argument to unsigned integer.
virtual void DynaShellCmdChainOut::doExec ( DynaShell shell,
ExecTup_T  tup[],
uint_t  uCount 
)
protectedpure virtual

Derived class specific execution function.

Parameters
shellDynamixel shell.
tupArray of (servo id, value) 2-tuples.
uCountNumber of tuples.

Implemented in DynaShellCmdWriteGoalSpeed, DynaShellCmdWriteTorqueEnable, DynaShellCmdCfgWriteServoMode, and DynaShellCmdMoveTo.

void DynaShellCmdChainOut::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
virtual

Execute 'write-like' command on servos.

Parameters
shellDynamixel shell.
argcCommand argument count.
argvArray of arguments.

Implements DynaShellCmd.

Definition at line 450 of file dynashell_cmd.cxx.

References DYNA_ID_NONE, DYNA_ID_NUMOF, DynaShell::Error(), DynaChain::IterNext(), DynaChain::IterNextMaster(), DynaChain::IterStart(), DynaChain::IterStartMaster(), ExecTup_T::m_nServoId, ExecTup_T::m_nVal, DynaShell::m_pDynaChain, and TRY.

451 {
452  uint_t uNumPairs;
454  int nServoId;
455  int nVal;
456  int iter;
457  int cnt;
458 
459  TRY( ChkArgCnt(shell, argc) );
460 
461  if( (argc % 2) != 0 )
462  {
463  shell.Error("Unmatched servo_id,value pairs.");
464  return;
465  }
466 
467  uNumPairs = (uint_t)(argc / 2);
468 
469  if( uNumPairs > DYNA_ID_NUMOF )
470  {
471  shell.Error("%u: Too many servo_id,value pairs.", uNumPairs);
472  return;
473  }
474 
475  TRY( ChkComm(shell) );
476  TRY( ChkChainNotEmpty(shell) );
477 
478  // full chain of servos
479  if( !strcmp(argv[0], "chain") )
480  {
481  TRY( ChkArgCntEQ(shell, argc, 2) );
482  TRY( ArgToInt(shell, argv[1], &nVal) );
483 
484  if( m_bMasterOpOnly )
485  {
486  for(nServoId = shell.m_pDynaChain->IterStartMaster(&iter), cnt=0;
487  nServoId != DYNA_ID_NONE;
488  nServoId = shell.m_pDynaChain->IterNextMaster(&iter), ++cnt)
489  {
490  tup[cnt].m_nServoId = nServoId;
491  tup[cnt].m_nVal = nVal;
492  }
493  }
494  else
495  {
496  for(nServoId = shell.m_pDynaChain->IterStart(&iter), cnt=0;
497  nServoId != DYNA_ID_NONE;
498  nServoId = shell.m_pDynaChain->IterNext(&iter), ++cnt)
499  {
500  tup[cnt].m_nServoId = nServoId;
501  tup[cnt].m_nVal = nVal;
502  }
503  }
504 
505  uNumPairs = (uint_t)cnt;
506  }
507 
508  // list of servos
509  else
510  {
511  for(iter=0, cnt=0; iter<argc; iter+=2, ++cnt)
512  {
513  TRY( ToInt(shell, argv[iter], &nServoId) );
514  TRY( ArgToInt(shell, argv[iter+1], &nVal) );
515  TRY( ChkChainHasServo(shell, nServoId) );
516  TRY( !m_bMasterOpOnly || ChkChainIsMasterServo(shell, nServoId) );
517 
518  tup[cnt].m_nServoId = nServoId;
519  tup[cnt].m_nVal = nVal;
520  }
521  }
522 
523  doExec(shell, tup, uNumPairs);
524 }
bool ChkChainNotEmpty(DynaShell &shell)
Check that the servo chain exists and is not empty.
bool ChkArgCntEQ(DynaShell &shell, int argc, int eq)
Check that the argument count is equal to the required.
int m_nServoId
servo id
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
bool ChkChainIsMasterServo(DynaShell &shell, int nServoId)
Check that the given servo is a master.
virtual int IterStartMaster(int *pIter)
Start iteration master servos over of entire servo chain.
Definition: DynaChain.cxx:1036
#define DYNA_ID_NUMOF
number of unique servo id&#39;s
Definition: Dynamixel.h:148
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
Definition: DynaChain.cxx:1058
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
Execute 2-tuple structure type.
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
virtual bool ChkArgCnt(DynaShell &shell, int argc)
Check that the argument count is within the class (min,max).
int m_nVal
value
#define TRY(boolexpr,...)
Try boolean expression.
Definition: dynashell_cmd.h:89
bool ChkComm(DynaShell &shell)
Check that Dynamixel communication exists and is open.
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
Definition: DynaChain.cxx:1020
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
bool m_bMasterOpOnly
is [not] a master-only supported operation
virtual void doExec(DynaShell &shell, ExecTup_T tup[], uint_t uCount)=0
Derived class specific execution function.
char * DynaShellCmdChainOut::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
virtual

Command tab completion generator.

Completes <servo_id> | chain NULL [servo_id NULL [servo_id NULL ...]]

Parameters
shellDynamixel shell.
sTextPartial text string to complete.
uTextLenLength of text.
nStateGenerator state. If FIRST, then initialize any statics.
sContextGenerator context (i.e. canonical command path).
Returns
If a first/next match is made, return allocated completed match.
Otherwise return NULL.

Reimplemented from DynaShellCmd.

Definition at line 541 of file dynashell_cmd.cxx.

References ReadLine::dupstr(), DYNA_ID_NONE, ReadLine::FIRST, DynaChain::GetNumberInChain(), DynaChain::GetNumberOfMastersInChain(), DynaChain::IterNext(), DynaChain::IterNextMaster(), DynaChain::IterStart(), DynaChain::IterStartMaster(), DynaShell::m_pDynaChain, and ReadLine::wc().

546 {
547  char buf[16];
548  int nArgNum;
549 
550  if( (shell.m_pDynaChain == NULL) ||
551  (shell.m_pDynaChain->GetNumberInChain() == 0) )
552  {
553  return NULL;
554  }
555 
556  else if( m_bMasterOpOnly &&
557  (shell.m_pDynaChain->GetNumberOfMastersInChain() == 0) )
558  {
559  return NULL;
560  }
561 
562  // argument number of already (expanded) arguments
563  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
564 
565  // every odd argument is the servo value, which cannot be expanded
566  if( nArgNum & 0x01 )
567  {
568  return NULL;
569  }
570 
571  //
572  // New command to complete - initialize.
573  //
574  if( nState == ReadLine::FIRST )
575  {
576  if( m_bMasterOpOnly )
577  {
579  }
580  else
581  {
583  }
584 
585  if( nArgNum == 0 )
586  {
587  m_bTabIncChain = true;
588  }
589  else
590  {
591  m_bTabIncChain = false;
592  }
593  }
594 
595  while( m_nTabServoId != DYNA_ID_NONE )
596  {
597  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
598  buf[sizeof(buf)-1] = 0;
599 
600  if( m_bMasterOpOnly )
601  {
603  }
604  else
605  {
607  }
608 
609  if( !strncmp(buf, sText, uTextLen) )
610  {
611  return ReadLine::dupstr(buf);
612  }
613  }
614 
615  if( m_bTabIncChain )
616  {
617  m_bTabIncChain = false;
618  if( !strncmp("chain", sText, uTextLen) )
619  {
620  return ReadLine::dupstr("chain");
621  }
622  }
623 
624  // no more matches
625  return NULL;
626 }
virtual uint_t GetNumberOfMastersInChain()
Get the number of servos currently in chain.
Definition: DynaChain.cxx:182
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
virtual int IterStartMaster(int *pIter)
Start iteration master servos over of entire servo chain.
Definition: DynaChain.cxx:1036
virtual int IterNextMaster(int *pIter)
Next iteration of master servos over of entire servo chain.
Definition: DynaChain.cxx:1058
virtual uint_t GetNumberInChain() const
Get the number of servos currently in chain.
Definition: DynaChain.h:140
char * m_sPubName
command&#39;s published name
static int wc(const string &str)
Count the words in the string.
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
int m_nTabIter
tab completion: servo id iterator
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
virtual int IterNext(int *pIter)
Next iteration over of entire servo chain.
Definition: DynaChain.cxx:1020
bool m_bTabIncChain
tab completion: [do not] include chain keyword
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360
bool m_bMasterOpOnly
is [not] a master-only supported operation
int m_nTabServoId
tab completion: current servo id

The documentation for this class was generated from the following files: