Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdReadMaxTorqueLimit Class Reference

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

Inheritance diagram for DynaShellCmdReadMaxTorqueLimit:
DynaShellCmd

Public Member Functions

virtual 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, int nServoId, uint_t uAddr)
 Read goal position for servo. 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

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

Definition at line 1158 of file dynashell_cmd_servo.cxx.

Member Function Documentation

virtual void DynaShellCmdReadMaxTorqueLimit::doExec ( DynaShell shell,
int  nServoId,
uint_t  uAddr 
)
inlineprotectedvirtual

Read goal position for servo.

Parameters
shellDynamixel shell.
nServoIdServo id.
uAddrServo read address.

Definition at line 1364 of file dynashell_cmd_servo.cxx.

References DYNA_OK, DynaShell::Error(), DynaShell::m_pDynaComm, DynaComm::Read16(), and DynaShell::Response().

1365  {
1366  uint_t uMaxTorqueLimit;
1367  int rc;
1368 
1369  rc = shell.m_pDynaComm->Read16(nServoId, uAddr, &uMaxTorqueLimit);
1370 
1371  if( rc != DYNA_OK )
1372  {
1373  shell.Error(rc, "Servo %d: Read maximum torque limit failed.", nServoId);
1374  return;
1375  }
1376 
1377  shell.Response("Servo %3d: %d\n", nServoId, uMaxTorqueLimit);
1378  }
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
DynaComm * m_pDynaComm
dynamixel bus communication
Definition: dynashell.h:359
virtual int Read16(int nServoId, uint_t uAddr, ushort_t *pVal)=0
Read a 16-bit value from Dynamixel servo control table.
void Response(const char *sFmt,...)
Print formatted success response.
Definition: dynashell.cxx:763
void Error(int rc, const char *sFmt,...)
Raise error on dynamixel error code.
Definition: dynashell.cxx:808
virtual void DynaShellCmdReadMaxTorqueLimit::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 1194 of file dynashell_cmd_servo.cxx.

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

1195  {
1196  uint_t uAddr;
1197  int nServoId;
1198  int iter;
1199 
1200  TRY( ChkArgCnt(shell, argc) );
1201  TRY( ChkComm(shell) );
1202  TRY( ChkChainNotEmpty(shell) );
1203 
1204  if( !strcmp(argv[0], "powerup") )
1205  {
1207  }
1208  else if( !strcmp(argv[0], "runtime") )
1209  {
1211  }
1212  else
1213  {
1214  shell.Error("%s: Unknown <which> value.", argv[0]);
1215  return;
1216  }
1217 
1218  if( !strcmp(argv[1], "chain") )
1219  {
1220  TRY( ChkArgCntEQ(shell, argc, 2) );
1221 
1222  for(nServoId = shell.m_pDynaChain->IterStart(&iter);
1223  nServoId != DYNA_ID_NONE;
1224  nServoId = shell.m_pDynaChain->IterNext(&iter))
1225  {
1226  doExec(shell, nServoId, uAddr);
1227  }
1228  }
1229 
1230  else
1231  {
1232  for(iter=1; iter<argc; ++iter)
1233  {
1234  TRY( ToInt(shell, argv[iter], &nServoId) );
1235  TRY( ChkChainHasServo(shell, nServoId) );
1236 
1237  doExec(shell, nServoId, uAddr);
1238  }
1239  }
1240  }
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.
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
virtual void doExec(DynaShell &shell, int nServoId, uint_t uAddr)
Read goal position for servo.
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
#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).
#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* DynaShellCmdReadMaxTorqueLimit::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 1257 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().

1262  {
1263  int nArgNum;
1264  char buf[16];
1265  int i;
1266 
1267  if( (shell.m_pDynaChain == NULL) ||
1268  (shell.m_pDynaChain->GetNumberInChain() == 0) )
1269  {
1270  return NULL;
1271  }
1272 
1273  // argument number of already (expanded) arguments
1274  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
1275 
1276  // <which>
1277  if( nArgNum == 0 )
1278  {
1279  if( nState == ReadLine::FIRST )
1280  {
1281  m_nTabIter = 0;
1282  }
1283 
1284  while( m_nTabIter < 2 )
1285  {
1286  i = m_nTabIter++;
1287 
1288  switch( i )
1289  {
1290  case 0:
1291  if( !strncmp("powerup", sText, uTextLen) )
1292  {
1293  return ReadLine::dupstr("powerup");
1294  }
1295  break;
1296  case 1:
1297  if( !strncmp("runtime", sText, uTextLen) )
1298  {
1299  return ReadLine::dupstr("runtime");
1300  }
1301  break;
1302  }
1303  }
1304  }
1305 
1306  //
1307  // Tab complete servo list
1308  //
1309  else
1310  {
1311  if( nState == ReadLine::FIRST )
1312  {
1314 
1315  if( nArgNum == 1 )
1316  {
1317  m_bTabIncChain = true;
1318  }
1319  else
1320  {
1321  m_bTabIncChain = false;
1322  }
1323  }
1324 
1325  while( m_nTabServoId != DYNA_ID_NONE )
1326  {
1327  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
1328  buf[sizeof(buf)-1] = 0;
1329 
1331 
1332  if( !strncmp(buf, sText, uTextLen) )
1333  {
1334  return ReadLine::dupstr(buf);
1335  }
1336  }
1337 
1338  if( m_bTabIncChain )
1339  {
1340  m_bTabIncChain = false;
1341  if( !strncmp("chain", sText, uTextLen) )
1342  {
1343  return ReadLine::dupstr("chain");
1344  }
1345  }
1346  }
1347 
1348  // no more matches
1349  return NULL;
1350  }
int m_nTabIter
tab completion: iterator
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
bool m_bTabIncChain
tab completion: [do not] include chain keyword
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
int m_nTabServoId
tab completion: current servo id
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

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