Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdWriteMaxTorqueLimit Class Reference

Write servos on power-up or run-time maximum torque limits. More...

Inheritance diagram for DynaShellCmdWriteMaxTorqueLimit:
DynaShellCmd

Public Member Functions

void Exec (DynaShell &shell, int argc, char *argv[])
 Execute 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, uint_t uAddr, ExecTup_T tup[], uint_t uCount)
 Move servos to goal positions. More...
 
- 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

int m_nTabIter
 tab completion: 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

Write servos on power-up or run-time maximum torque limits.

Definition at line 1389 of file dynashell_cmd_servo.cxx.

Member Function Documentation

virtual void DynaShellCmdWriteMaxTorqueLimit::doExec ( DynaShell shell,
uint_t  uAddr,
ExecTup_T  tup[],
uint_t  uCount 
)
inlineprotectedvirtual

Move servos to goal positions.

Parameters
shellDynamixel shell.
uAddrTorque limit address.
tupArray of (servo id, goal position) 2-tuples.
uCountNumber of tuples.

Definition at line 1635 of file dynashell_cmd_servo.cxx.

References DYNA_OK, DynaShell::Error(), ExecTup_T::m_nServoId, DynaShell::m_pDynaComm, and DynaComm::Write16().

1639  {
1640  int nServoId;
1641  uint_t uVal;
1642  uint_t i;
1643  int rc;
1644 
1645  for(i=0, rc=DYNA_OK; i<uCount && rc==DYNA_OK; ++i)
1646  {
1647  nServoId = tup[i].m_nServoId;
1648  uVal = (uint_t)tup[i].m_nVal;
1649 
1650  rc = shell.m_pDynaComm->Write16(nServoId, uAddr, uVal);
1651 
1652  if( rc != DYNA_OK )
1653  {
1654  shell.Error(rc,
1655  "Servo %d: Write maximum torque limit at 0x%02x with %u failed.",
1656  nServoId, uAddr, uVal);
1657  }
1658  }
1659  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
int m_nServoId
servo id
DynaComm * m_pDynaComm
dynamixel bus communication
Definition: dynashell.h:359
virtual int Write16(int nServoId, uint_t uAddr, ushort_t uhVal)=0
Write a 16-bit value to Dynamixel servo control table.
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
void DynaShellCmdWriteMaxTorqueLimit::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Execute command on servos.

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

Implements DynaShellCmd.

Definition at line 1428 of file dynashell_cmd_servo.cxx.

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

1429  {
1430  uint_t uAddr;
1431  uint_t uNumPairs;
1432  ExecTup_T tup[DYNA_ID_NUMOF];
1433  int nServoId;
1434  int nVal;
1435  int iter;
1436  int cnt;
1437 
1438  TRY( ChkArgCnt(shell, argc) );
1439 
1440  if( ((argc-1) % 2) != 0 )
1441  {
1442  shell.Error("Unmatched servo_id,value pairs.");
1443  return;
1444  }
1445 
1446  if( !strcmp(argv[0], "powerup") )
1447  {
1449  }
1450  else if( !strcmp(argv[0], "runtime") )
1451  {
1453  }
1454  else
1455  {
1456  shell.Error("%s: Unknown <which> value.", argv[0]);
1457  return;
1458  }
1459 
1460  uNumPairs = (uint_t)((argc-1) / 2);
1461 
1462  if( uNumPairs > DYNA_ID_NUMOF )
1463  {
1464  shell.Error("%u: Too many servo_id,value pairs.", uNumPairs);
1465  return;
1466  }
1467 
1468  TRY( ChkComm(shell) );
1469  TRY( ChkChainNotEmpty(shell) );
1470 
1471  // full chain of servos
1472  if( !strcmp(argv[1], "chain") )
1473  {
1474  TRY( ChkArgCntEQ(shell, argc, 3) );
1475  TRY( ToInt(shell, argv[2], &nVal) );
1476 
1477  for(nServoId = shell.m_pDynaChain->IterStart(&iter), cnt=0;
1478  nServoId != DYNA_ID_NONE;
1479  nServoId = shell.m_pDynaChain->IterNext(&iter), ++cnt)
1480  {
1481  tup[cnt].m_nServoId = nServoId;
1482  tup[cnt].m_nVal = nVal;
1483  }
1484 
1485  uNumPairs = (uint_t)cnt;
1486  }
1487 
1488  // list of servos
1489  else
1490  {
1491  for(iter=1, cnt=0; iter<argc-1; iter+=2, ++cnt)
1492  {
1493  TRY( ToInt(shell, argv[iter], &nServoId) );
1494  TRY( ToInt(shell, argv[iter+1], &nVal) );
1495  TRY( ChkChainHasServo(shell, nServoId) );
1496 
1497  tup[cnt].m_nServoId = nServoId;
1498  tup[cnt].m_nVal = nVal;
1499  }
1500  }
1501 
1502  doExec(shell, uAddr, tup, uNumPairs);
1503  }
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.
virtual void doExec(DynaShell &shell, uint_t uAddr, ExecTup_T tup[], uint_t uCount)
Move servos to goal positions.
int m_nServoId
servo id
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
#define DYNA_ID_NUMOF
number of unique servo id&#39;s
Definition: Dynamixel.h:148
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
Execute 2-tuple structure type.
#define DYNA_ADDR_LIM_TORQUE_MAX_LSB
current torque limit lsb (RW)
Definition: Dynamixel.h:965
#define DYNA_ADDR_LIM_TORQUE_MAX_ON_LSB
maximum torque lsb (RW)
Definition: Dynamixel.h:589
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
virtual char* DynaShellCmdWriteMaxTorqueLimit::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

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

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 1521 of file dynashell_cmd_servo.cxx.

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

1526  {
1527  int nArgNum;
1528  char buf[16];
1529  int i;
1530 
1531  if( (shell.m_pDynaChain == NULL) ||
1532  (shell.m_pDynaChain->GetNumberInChain() == 0) )
1533  {
1534  return NULL;
1535  }
1536 
1537  // argument number of already (expanded) arguments
1538  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
1539 
1540  // <which>
1541  if( nArgNum == 0 )
1542  {
1543  if( nState == ReadLine::FIRST )
1544  {
1545  m_nTabIter = 0;
1546  }
1547 
1548  while( m_nTabIter < 2 )
1549  {
1550  i = m_nTabIter++;
1551 
1552  switch( i )
1553  {
1554  case 0:
1555  if( !strncmp("powerup", sText, uTextLen) )
1556  {
1557  return ReadLine::dupstr("powerup");
1558  }
1559  break;
1560  case 1:
1561  if( !strncmp("runtime", sText, uTextLen) )
1562  {
1563  return ReadLine::dupstr("runtime");
1564  }
1565  break;
1566  }
1567  }
1568  }
1569 
1570  // every even argument is the servo value, which cannot be expanded
1571  else if( !(nArgNum & 0x01) )
1572  {
1573  return NULL;
1574  }
1575 
1576  //
1577  // Tab complete servo list
1578  //
1579  else
1580  {
1581  if( nState == ReadLine::FIRST )
1582  {
1584 
1585  if( nArgNum == 1 )
1586  {
1587  m_bTabIncChain = true;
1588  }
1589  else
1590  {
1591  m_bTabIncChain = false;
1592  }
1593  }
1594 
1595  while( m_nTabServoId != DYNA_ID_NONE )
1596  {
1597  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
1598  buf[sizeof(buf)-1] = 0;
1599 
1601 
1602  if( !strncmp(buf, sText, uTextLen) )
1603  {
1604  return ReadLine::dupstr(buf);
1605  }
1606  }
1607 
1608  if( m_bTabIncChain )
1609  {
1610  m_bTabIncChain = false;
1611  if( !strncmp("chain", sText, uTextLen) )
1612  {
1613  return ReadLine::dupstr("chain");
1614  }
1615  }
1616  }
1617 
1618  // no more matches
1619  return NULL;
1620  }
bool m_bTabIncChain
tab completion: [do not] include chain keyword
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
virtual uint_t GetNumberInChain() const
Get the number of servos currently in chain.
Definition: DynaChain.h:140
int m_nTabIter
tab completion: iterator
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
#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
int m_nTabServoId
tab completion: current servo id

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