Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
DynaShellCmdTrain Class Reference

Record dynamixel chain movements. More...

Inheritance diagram for DynaShellCmdTrain:
DynaShellCmd

Public Member Functions

 DynaShellCmdTrain ()
 Default constructor.
 
virtual ~DynaShellCmdTrain ()
 Default destructor.
 
virtual void Exec (DynaShell &shell, int argc, char *argv[])
 Execute recording. 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

void RecordTraining (DynaShell &shell, int nStartDelay, int nSamplePeriod)
 Record the movements of a dynamixel chain. 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_nTabIndex
 tab completion: keyword index
 
- 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

Record dynamixel chain movements.

Definition at line 1267 of file dynashell_cmd_train.cxx.

Member Function Documentation

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

Execute recording.

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

Implements DynaShellCmd.

Definition at line 1296 of file dynashell_cmd_train.cxx.

References DYNA_ID_NONE, DynaServo::GetModelNumber(), DynaChain::GetServo(), DynaChain::IterNextMaster(), DynaChain::IterStartMaster(), DynaShell::m_pDynaChain, DynaShell::m_pRecording, DynaShell::RecordingInit(), DynaRecording::RegisterServoInfo(), and TRY.

1297  {
1298  int nStartDelay;
1299  int nSamplePeriod;
1300  int iter;
1301  int nServoId;
1302  DynaServo *pServo;
1303 
1304  //
1305  // Parse arguments
1306  //
1307  TRY( ChkArgCnt(shell, argc) );
1308  TRY( ToInt(shell, argv[0], &nStartDelay) );
1309  TRY( ToInt(shell, argv[1], &nSamplePeriod) );
1310 
1311  //
1312  // Check state
1313  //
1314  TRY( ChkComm(shell) );
1315  TRY( ChkChainNotEmpty(shell) );
1316 
1317 
1318  // initialize recording data
1319  shell.RecordingInit(nSamplePeriod);
1320 
1321  // register servos in chain to be trained with recording header
1322  for(nServoId = shell.m_pDynaChain->IterStartMaster(&iter);
1323  nServoId != DYNA_ID_NONE;
1324  nServoId = shell.m_pDynaChain->IterNextMaster(&iter))
1325  {
1326  pServo = shell.m_pDynaChain->GetServo(nServoId);
1327  shell.m_pRecording->RegisterServoInfo(nServoId, pServo->GetModelNumber());
1328  }
1329 
1330  // record training session
1331  RecordTraining(shell, nStartDelay, nSamplePeriod);
1332  }
bool ChkChainNotEmpty(DynaShell &shell)
Check that the servo chain exists and is not empty.
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
DynaRecording * m_pRecording
dynamixel recording
Definition: dynashell.h:362
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
bool ToInt(DynaShell &shell, const char *sArg, int *pVal)
Convert command argument to integer.
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
virtual uint_t GetModelNumber() const
Get servo model number.
Definition: DynaServo.h:125
bool ChkComm(DynaShell &shell)
Check that Dynamixel communication exists and is open.
void RecordTraining(DynaShell &shell, int nStartDelay, int nSamplePeriod)
Record the movements of a dynamixel chain.
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
virtual int RegisterServoInfo(int nServoId, uint_t uModelNum)
Register servo information in recording header.
DynaChain * m_pDynaChain
dynamixel chain
Definition: dynashell.h:360
void RecordingInit(int nSamplePeriod, const char *sDate=NULL)
(Re)Initialize recording.
Definition: dynashell.h:383
void DynaShellCmdTrain::RecordTraining ( DynaShell shell,
int  nStartDelay,
int  nSamplePeriod 
)
inlineprotected

Record the movements of a dynamixel chain.

Parameters
shellDynamixel shell.
nStartDelayDelay in seconds, before recording starts.
nSamplePeriodRecording sample period (ms)

Definition at line 1402 of file dynashell_cmd_train.cxx.

References DynaRecording::AddFieldTuple(), DynaRecording::AddRecord(), DYNA_ID_NONE, DYNA_OK, DynaRecording::END, DynaShell::Error(), DynaChain::GetServo(), DynaChain::IterNextMaster(), DynaChain::IterStartMaster(), DynaShell::m_pDynaChain, DynaShell::m_pRecording, and waitkey().

1405  {
1406  DynaRecording *pRecording = shell.m_pRecording;
1407  int nRecNum;
1408  int iter;
1409  int nServoId;
1410  DynaServo *pServo;
1411  int nCurPos;
1412  int nCurSpeed;
1413  int rc;
1414 
1415  if( nSamplePeriod < 1 )
1416  {
1417  nSamplePeriod = 1;
1418  }
1419 
1420  printf("Starting to record in %u seconds.\n", nStartDelay);
1421  printf(" Recording sample rate: %dms.\n", nSamplePeriod);
1422  printf("Press <CR> to stop recording.\n\n");
1423  fflush(stdout);
1424 
1425  // count down
1426  for(iter=0; iter<nStartDelay; ++iter)
1427  {
1428  printf("%d ", nStartDelay-iter);
1429  fflush(stdout);
1430  sleep(1);
1431  }
1432 
1433  printf("Go\n\n");
1434 
1435  //
1436  // Add record at sampling rate
1437  //
1438  while( (nRecNum = pRecording->AddRecord()) != DynaRecording::END )
1439  {
1440  printf("record[%d]: ", nRecNum);
1441 
1442  //
1443  // Record current position and speed for each master servo in chain.
1444  //
1445  for(nServoId = shell.m_pDynaChain->IterStartMaster(&iter);
1446  nServoId != DYNA_ID_NONE;
1447  nServoId = shell.m_pDynaChain->IterNextMaster(&iter))
1448  {
1449  pServo = shell.m_pDynaChain->GetServo(nServoId);
1450 
1451  // get current position
1452  rc = pServo->ReadCurPos(&nCurPos);
1453 
1454  if( rc != DYNA_OK )
1455  {
1456  shell.Error(rc, "Servo %d: ReadCurPos.", nServoId);
1457  return;
1458  }
1459 
1460  // RDK TODO check alarms for out-of-range servo positions
1461 
1462  // get current speed
1463  rc = pServo->ReadCurSpeed(&nCurSpeed);
1464 
1465  if( rc != DYNA_OK )
1466  {
1467  shell.Error(rc, "Servo %d: ReadCurSpeed.", nServoId);
1468  return;
1469  }
1470 
1471  // and field tuple to record
1472  pRecording->AddFieldTuple(nRecNum, nServoId, nCurPos, nCurSpeed);
1473 
1474  printf("%d %d %d ", nServoId, nCurPos, nCurSpeed);
1475  }
1476 
1477  printf("\n");
1478 
1479  // recording sample period wait and user <CR> stop
1480  if( waitkey(nSamplePeriod) )
1481  {
1482  break;
1483  }
1484  }
1485  }
static bool_t waitkey(int nMSec)
Block, waiting for either timeout or user keyboard press.
#define DYNA_OK
not an error, success
Definition: Dynamixel.h:78
virtual int AddRecord()
Add a new empty record to the recording.
virtual int AddFieldTuple(int nRecNum, int nServoId, int nPos, int nSpeed)
Add new recording field tuple.
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
DynaRecording * m_pRecording
dynamixel recording
Definition: dynashell.h:362
Dynamixel Servo Abstract Base Class.
Definition: DynaServo.h:78
static const int END
past-the-end mark
virtual DynaServo * GetServo(int nServoId)
Definition: DynaChain.h:129
#define DYNA_ID_NONE
no servo id
Definition: Dynamixel.h:145
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* DynaShellCmdTrain::TabCompletion ( DynaShell shell,
const char *  sText,
size_t  uTextLen,
int  nState,
const char *  sContext 
)
inlinevirtual

Command tab completion generator.

Completes NULL NULL <loop>

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 1349 of file dynashell_cmd_train.cxx.

References ReadLine::dupstr(), ReadLine::FIRST, and ReadLine::wc().

1354  {
1355  // direction keyword table
1356  static const char *keywordsLoop[] = {"close", "open"};
1357 
1358  int nArgNum;
1359  const char *s;
1360  char buf[16];
1361 
1362  // argument number of already (expanded) arguments
1363  nArgNum = ReadLine::wc(sContext) - ReadLine::wc(m_sPubName);
1364 
1365  if( nArgNum != 2 )
1366  {
1367  return NULL;
1368  }
1369 
1370  //
1371  // New command argument to complete - initialize.
1372  //
1373  if( nState == ReadLine::FIRST )
1374  {
1375  m_nTabIndex = 0;
1376  }
1377 
1378  while( m_nTabIndex < arraysize(keywordsLoop) )
1379  {
1380  s = keywordsLoop[m_nTabIndex++];
1381 
1382  if( !strncmp(s, sText, uTextLen) )
1383  {
1384  return ReadLine::dupstr(s);
1385  }
1386  }
1387 
1388  // no more matches
1389  return NULL;
1390  }
int m_nTabIndex
tab completion: keyword index
static const int FIRST
first state
static char * dupstr(const string &str)
Duplicate string.
char * m_sPubName
command&#39;s published name
static int wc(const string &str)
Count the words in the string.

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