Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdSetPid Class Reference

Get the PID values for the given servos. More...

Inheritance diagram for DynaShellCmdSetPid:
DynaShellCmd

Public Member Functions

void Exec (DynaShell &shell, int argc, char *argv[])
 Execute 'read-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, DynaServo *pServo, double fKp, double fKi, double fKd)
 Get servo PID parameters. 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: servo id iterator
 
int m_nTabServoId
 tab completion: current servo id
 
- 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

Get the PID values for the given servos.

Definition at line 214 of file dynashell_cmd_train.cxx.

Member Function Documentation

virtual void DynaShellCmdSetPid::doExec ( DynaShell shell,
DynaServo pServo,
double  fKp,
double  fKi,
double  fKd 
)
inlineprotectedvirtual

Get servo PID parameters.

Parameters
shellDynamixel shell.
pServoPointer to servo.
fKpPID proportional constant.
fKiPID integral constant.
fKdPID derivative constant.

Definition at line 395 of file dynashell_cmd_train.cxx.

400  {
401  pServo->GetSpeedPid().SetConstants(fKp, fKi, fKd);
402  }
void DynaShellCmdSetPid::Exec ( DynaShell shell,
int  argc,
char *  argv[] 
)
inlinevirtual

Execute 'read-like' command on servos.

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

Implements DynaShellCmd.

Definition at line 249 of file dynashell_cmd_train.cxx.

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

250  {
251  bool bAll;
252  int nServoId;
253  double fKp;
254  double fKi;
255  double fKd;
256  int i;
257  int iter;
258  DynaServo *pServo;
259 
260  TRY( ChkArgCnt(shell, argc) );
261 
262  TRY( ChkComm(shell) );
263  TRY( ChkChainNotEmpty(shell) );
264 
265  for(i=0; i<argc; ++i)
266  {
267  switch( i )
268  {
269  case 0:
270  if( !strcmp(argv[i], "chain") )
271  {
272  bAll = true;
273  }
274  else
275  {
276  TRY( ToInt(shell, argv[i], &nServoId) );
277  TRY( ChkChainHasServo(shell, nServoId) );
278  bAll = false;
279  }
280  break;
281  case 1:
282  TRY( ToDouble(shell, argv[i], &fKp) );
283  break;
284  case 2:
285  TRY( ToDouble(shell, argv[i], &fKi) );
286  break;
287  case 3:
288  TRY( ToDouble(shell, argv[i], &fKd) );
289  break;
290  default:
291  shell.Error("Huh?");
292  return;
293  }
294  }
295 
296  if( bAll )
297  {
298  for(nServoId = shell.m_pDynaChain->IterStart(&iter);
299  nServoId != DYNA_ID_NONE;
300  nServoId = shell.m_pDynaChain->IterNext(&iter))
301  {
302  pServo = shell.m_pDynaChain->GetServo(nServoId);
303  doExec(shell, pServo, fKp, fKi, fKd);
304  }
305  }
306  else
307  {
308  pServo = shell.m_pDynaChain->GetServo(nServoId);
309  doExec(shell, pServo, fKp, fKi, fKd);
310  }
311  }
bool ChkChainNotEmpty(DynaShell &shell)
Check that the servo chain exists and is not empty.
bool ChkChainHasServo(DynaShell &shell, int nServoId)
Check that the given servo is present in the chain.
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
bool ToDouble(DynaShell &shell, const char *sArg, double *pVal)
Convert command argument to double.
virtual void doExec(DynaShell &shell, DynaServo *pServo, double fKp, double fKi, double fKd)
Get servo PID parameters.
virtual int IterStart(int *pIter)
Start iteration over of entire servo chain.
Definition: DynaChain.cxx:1008
virtual DynaServo * GetServo(int nServoId)
Definition: DynaChain.h:129
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* DynaShellCmdSetPid::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes NULL <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 328 of file dynashell_cmd_train.cxx.

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

333  {
334  int nArgNum;
335  char buf[16];
336 
337  if( (shell.m_pDynaChain == NULL) ||
338  (shell.m_pDynaChain->GetNumberInChain() == 0) )
339  {
340  return NULL;
341  }
342 
343  // argument number of already (expanded) arguments
344  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
345 
346  // only first argument can be expanded
347  if( nArgNum > 0 )
348  {
349  return NULL;
350  }
351 
352  //
353  // New command to complete - initialize.
354  //
355  if( nState == ReadLine::FIRST )
356  {
358  }
359 
360  while( m_nTabServoId != DYNA_ID_NONE )
361  {
362  snprintf(buf, sizeof(buf), "%d", m_nTabServoId);
363  buf[sizeof(buf)-1] = 0;
364 
366 
367  if( !strncmp(buf, sText, uTextLen) )
368  {
369  return ReadLine::dupstr(buf);
370  }
371  }
372 
373  if( !strncmp("chain", sText, uTextLen) )
374  {
375  return ReadLine::dupstr("chain");
376  }
377 
378  // no more matches
379  return NULL;
380  }
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
char * m_sPubName
command&#39;s published name
int m_nTabServoId
tab completion: current servo id
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_nTabIter
tab completion: servo id iterator

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