peripherals  1.4.2
RoadNarrows Robotics Hardware Peripherals Package
rnr::MotRoboteqSmall Class Reference
Inheritance diagram for rnr::MotRoboteqSmall:
rnr::Mot

Public Member Functions

 MotRoboteqSmall (float maxSpeed, float minSpeed, float speedStepSize, float maxBrake, float minBrake, float brakeStepSize)
 
int open (const std::string &devName, int baudRate)
 Function opens serial communication with motor controller device. More...
 
int close ()
 Function closes serial communication with motor controller device. More...
 
int sendCommand (int fd, byte_t *buf, int nBytes, int timeout)
 
int recvResponse (int fd, byte_t *buf, int timeout)
 
bool motIDIsValid (int motID)
 Function sends commands to the motor controller and receives responses from the motor controller. More...
 
int setSpeed (int motID, float speed, units_t units=units_norm)
 Description. More...
 
int setSpeed (VecSpeedTupples vecSpeedTupple, units_t units=units_norm)
 Function updates the speed of all motors simultaneously but individually. More...
 
int setSpeedRaw (int motID, int speed)
 
int setSpeedRaw (VecSpeedRawTupples vecSpeedRawTupple)
 
int stop (int motID)
 Function stops motor specified. More...
 
int stop ()
 
int eStop ()
 Function simultaneously halts motor rotation for all motors by setting speeds to zero. More...
 
int eStopRelease ()
 Function releases emergency stop condition and allows normal ops. More...
 
int getCurrent (int motID, units_t units=units_amp)
 Function retrieves value for current load on a single motor. More...
 
int getCurrentLimits ()
 Function determines if a motor controller can monitor current. More...
 
int setCurrentLimits (int motID, int current, units_t units=units_amp)
 Function sets minimum and maximum limits for current. More...
 
int getVoltageLimits ()
 Function retrieves value for current load on a single motor. More...
 
int setVoltageLimits (int lowVoltage, int overVoltage)
 Function sets the minimum and maximum limits for applied voltage for all motors. More...
 
int getVoltage ()
 Function retrieves value for voltage applied to a single motor. More...
 
int setSpeedProfile (int motID, int accel, int decel=DEF_DEC)
 Function retrieves value for voltage applied to a single motor. More...
 
- Public Member Functions inherited from rnr::Mot
 Mot (float maxSpeed, float minSpeed, float speedStepSize, float maxBrake, float minBrake, float brakeStepSize)
 

Protected Attributes

int m_fd
 
int m_ntimeout
 
int m_nbaudRate
 
- Protected Attributes inherited from rnr::Mot
float m_fMaxSpeed
 Function sets the acce1 leration rate for motors. More...
 
float m_fMinSpeed
 
float m_fSpeedStepSize
 
float m_fMaxBrake
 
float m_fMinBrake
 
float m_fBrakeStepSize
 

Additional Inherited Members

- Public Types inherited from rnr::Mot
typedef std::vector< IDFloatTuppleVecSpeedTupples
 
typedef std::vector< IDIntTuppleVecSpeedRawTupples
 
typedef std::vector< int > VecMotID
 

Detailed Description

Definition at line 64 of file MotRoboteqSmall.h.

Member Function Documentation

int MotRoboteqSmall::close ( )
virtual

Function closes serial communication with motor controller device.

Uses SerDevClose to close serial connection. Returns: 0 on success, -1 on fail.

Implements rnr::Mot.

Definition at line 99 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

100 {
101  return SerDevClose(m_fd);
102 }
int MotRoboteqSmall::eStop ( )
virtual

Function simultaneously halts motor rotation for all motors by setting speeds to zero.

Needs to be passed:

Function simultaneously halts motor rotation for all motors and locks the motor controller. No further commands can be given until EStop Release function has been passed.

Implements rnr::Mot.

Definition at line 243 of file MotRoboteqSmall.cxx.

244 {
245  setSpeedRaw(1, 0);
246  setSpeedRaw(2, 0);
247 
248  char buf[32];
249 
250  char cmd[32];
251  char res[32];
252  sprintf(cmd,"!EX\r");
253  int nBytes = strlen(cmd);
254 
255  sendCommand(m_fd, (byte_t*)cmd, nBytes, m_ntimeout);
256  recvResponse(m_fd, (byte_t*)res, m_ntimeout);
257  // check +/-
258  if (buf[0] =='-')
259  {
260  LOGERROR("setSpeedRaw(vec) command failed\nIs firmware updated?\n");
261  return -1;
262  }
263 }
int MotRoboteqSmall::eStopRelease ( )
virtual

Function releases emergency stop condition and allows normal ops.

Implements rnr::Mot.

Definition at line 265 of file MotRoboteqSmall.cxx.

266 {
267  setSpeedRaw(1, 0);
268  setSpeedRaw(2, 0);
269 
270  char buf[32];
271 
272  char cmd[32];
273  char res[32];
274  sprintf(cmd,"!MG\r");
275  int nBytes = strlen(cmd);
276 
277  sendCommand(m_fd, (byte_t*)cmd, nBytes, m_ntimeout);
278  recvResponse(m_fd, (byte_t*)res, m_ntimeout);
279  // check +/-
280  if (buf[0] =='-')
281  {
282  LOGERROR("setSpeedRaw(vec) command failed\nIs firmware updated?\n");
283  return -1;
284  }
285 }
int MotRoboteqSmall::getCurrent ( int  motID,
units_t  units = units_amp 
)
virtual

Function retrieves value for current load on a single motor.

Implements rnr::Mot.

Definition at line 287 of file MotRoboteqSmall.cxx.

288 {
289  if (!motIDIsValid(motID))
290  {
291  return -1;
292  }
293 
294  char cmd[32];
295  char res[32];
296  sprintf(cmd,"?A %d\r", motID);
297  int nBytes = strlen(cmd);
298 
299  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
300  recvResponse(m_fd, (byte_t *)res, m_ntimeout);
301 
302  // TODO : parse response
303 
304  return 0;
305 }
bool motIDIsValid(int motID)
Function sends commands to the motor controller and receives responses from the motor controller...
int MotRoboteqSmall::getCurrentLimits ( )
virtual

Function determines if a motor controller can monitor current.

If feature is not defined by the user, the controller will not monitor current.

Function obtains current limit vaules from motor controller.

Implements rnr::Mot.

Definition at line 307 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

308 {
309  char cmd[32];
310  char res[32];
311  sprintf(cmd,"~ALIM\r");
312  int nBytes = strlen(cmd);
313 
314  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
315  recvResponse(m_fd, (byte_t*)res, m_ntimeout);
316 
317  // TODO : parse response
318 
319  return 0;
320 }
int MotRoboteqSmall::getVoltage ( )
virtual

Function retrieves value for voltage applied to a single motor.

Implements rnr::Mot.

Definition at line 362 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

363 {
364  char cmd[32];
365  char res[32];
366  sprintf(cmd,"?V\r");
367  int nBytes = strlen(cmd);
368 
369  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
370  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
371 
372  // TODO : parse response
373  return 0;
374 }
int MotRoboteqSmall::getVoltageLimits ( )
virtual

Function retrieves value for current load on a single motor.

Function sets value for current supplied to a single motor.

Function sets value for current supplied to a single motor.

Function determines is a motor controller can monitor voltage.

If feature is not defined by the user, the controller will not monitor voltage.

Function retrieves voltage limits from motor controller.

Implements rnr::Mot.

Definition at line 346 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

347 {
348  char cmd[32];
349  char res[32];
350  sprintf(cmd,"~UVL_~OVL\r");
351  int nBytes = strlen(cmd);
352 
353  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
354 
355  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
356  // TODO : parse response
357  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
358  // TODO : parse response
359  return 0;
360 }
bool MotRoboteqSmall::motIDIsValid ( int  motID)
virtual

Function sends commands to the motor controller and receives responses from the motor controller.

Function uses SerDevWrite (libserial) to send commands over serial to the motor controllers, and uses recvResponse to receive echoed command responses as well as acknowledgements and query responses.

Returns:

Function is responsible for retrieving responses from motor controllers after a command has been sent.

Returns: nBytes (number of bytes sent in response) on success

Function checks for valid motor ID inputs.

Returns: 0 on success, -1 on fail.

Implements rnr::Mot.

Definition at line 131 of file MotRoboteqSmall.cxx.

132 {
133  if (motID >2 || motID <1)
134  {
135  LOGDIAG3("Not a valid motor ID.\n");
136  return false;
137  }
138  return true;
139 }
int MotRoboteqSmall::open ( const std::string &  devName,
int  baudRate 
)
virtual

Function opens serial communication with motor controller device.

Uses SerDevOpen to open serial connection with device (devName) Returns: File descriptor >=0 on success, -1 on fail.

Implements rnr::Mot.

Definition at line 87 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

88 {
89  LOGDIAG3("jnt devName= %s baudRate= %d \n", devName.c_str(), baudRate);
90  if ((m_fd=SerDevOpen(devName.c_str(),baudRate,8,'N',1,0,0))==-1)
91  {
92  fprintf(stderr, "dhp -here\n");
93  return -1;
94  }
95  fprintf(stderr, "dhp -here 2\n");
96  return 0;
97 }
int MotRoboteqSmall::setCurrentLimits ( int  motID,
int  current,
units_t  units = units_amp 
)
virtual

Function sets minimum and maximum limits for current.

alim

Implements rnr::Mot.

Definition at line 322 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

323 {
324  char buf[32];
325 
326  char cmd[32];
327  char res[32];
328  //todo: compare current argument to 75% of SDC2130 rating.
329  int rawCurrent = current *10;
330  sprintf(cmd,"^ALIM %d %d\r", motID, rawCurrent);
331  int nBytes = strlen(cmd);
332 
333  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
334  recvResponse(m_fd, (byte_t*)res, m_ntimeout);
335 
336  // check response +/-
337  if (buf[0] =='-')
338  {
339  LOGERROR("setSpeedRaw(vec) command failed\n");
340  return -1;
341  }
342 
343  return 0;
344 }
int MotRoboteqSmall::setSpeed ( int  motID,
float  speed,
units_t  units = units_norm 
)
virtual

Description.

Parameters
iddes
[out]minSpeeddes
Returns

Description

Parameters
iddes
[out]minSpeeddesmotSpeeds
Returns

motSpeeds

Function retrieves the speed of a specific motor.

Raw speed will be given.

Needs to be passed: Motor ID (1 or 2)

Returns: 0 on success, -1 upon failure.

Function updates the speed of a single motor.

Needs to be passed: A speed (-1 <= speed <= 1), and a motor id (0 = left, 1 = right) Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.

Implements rnr::Mot.

Definition at line 141 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

142 {
143  int rawSpeed;
144  if (!motIDIsValid(motID))
145  {
146  return -1;
147  }
148 
149  if (units == units_norm)
150  {
151  if (speed >1 || speed <-1)
152  {
153  LOGDIAG3("Not a valid normalized motor speed.\n");
154  return -1;
155  }
156  rawSpeed=(int)(speed*1000);
157  }
158 
159  return setSpeedRaw(motID, rawSpeed);
160 }
bool motIDIsValid(int motID)
Function sends commands to the motor controller and receives responses from the motor controller...
int MotRoboteqSmall::setSpeed ( VecSpeedTupples  vecSpeedTupple,
units_t  units = units_norm 
)
virtual

Function updates the speed of all motors simultaneously but individually.

Function uses a vector to consturct a string of commands which will then be sent to multiple motors.

Needs to be passed: motSpeeds vetor which includes a Motor ID (1 or 2) and a value between or equal to -1 and 1 for speed.

Implements rnr::Mot.

Definition at line 162 of file MotRoboteqSmall.cxx.

163 {
164  VecSpeedTupples::iterator iter;
165  VecSpeedRawTupples vecSpeedRawTupple;
166  for (iter=vecSpeedTupple.begin();iter!=vecSpeedTupple.end();iter++)
167  {
168  IDFloatTupple src = *iter;
169  IDIntTupple dest;
170  if (!motIDIsValid(src.m_nMotID))
171  {
172  return -1;
173  }
174  dest.m_nMotID = src.m_nMotID;
175  if (src.m_fVal >1 || src.m_fVal <-1)
176  {
177  LOGDIAG3("Not a valid normalized motor speed. \n");
178  return -1;
179  }
180  dest.m_nVal = (int)(1000 * src.m_fVal);
181  vecSpeedRawTupple.push_back(dest);
182  }
183  setSpeedRaw(vecSpeedRawTupple);
184  return -1;
185 }
bool motIDIsValid(int motID)
Function sends commands to the motor controller and receives responses from the motor controller...
int MotRoboteqSmall::setSpeedProfile ( int  motID,
int  accel,
int  decel = DEF_DEC 
)
virtual

Function retrieves value for voltage applied to a single motor.

Function sets voltage value for an indivifual motor.

Function sets voltage value for an individual motor.

Function determines if a motor controller can monitor torque.

If feature is not defined by the user, the controller will not monitor torque.

Function retrieves value for torque output for a single motor.

Function sets minimum and maximum limits for motor torque.

\ brief Function retrives tourque values from an individual motor.

\ brief Function retrives tourque values from an individual motor.

Function sets the torque value for an individual motor.

Higher torque values give the motor more turning strength.

Function sets the torque value for an individual motor.

Higher torque values give the motor more turning strength.

Function sets the acceleration rate for motors.

Values represent 'slope' of the velocity profile when motor speeds are changed. In the case of deceleration, this is analogous to the difference between coasting to a stop (high argument values) and stopping abruptly (low argument values).

Function sets the acceleration rate for motors.

Values represent 'slope' of the velocity profile when motor speeds are changed. In the case of deceleration, this is analogous to the difference between coasting to a stop (high argument values) and stopping abruptly (low argument values).

Implements rnr::Mot.

Definition at line 414 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

415 {
416  if (decel==DEF_DEC)
417  {
418  decel=accel;
419  }
420 
421  char buf[32];
422 
423  char cmd[32];
424  char res[32];
425  sprintf(cmd,"^MAC %d %d_^MDEC %d %d\r", motID, accel, motID, decel);
426  int nBytes = strlen(cmd);
427 
428  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
429  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
430  // check +/-
431  if (buf[0] =='-')
432  {
433  LOGERROR("setSpeedProfile() command failed\n");
434  return -1;
435  }
436  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
437  // check +/-
438  if (buf[0] =='-')
439  {
440  LOGERROR("setSpeedProfile() command failed\n");
441  return -1;
442  }
443 
444  return 0;
445 
446 }
int MotRoboteqSmall::setVoltageLimits ( int  lowVoltage,
int  overVoltage 
)
virtual

Function sets the minimum and maximum limits for applied voltage for all motors.

Needs to be passed: Low Voltage limit (>=5) and a Over Voltage limit (>=29).

Implements rnr::Mot.

Definition at line 376 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

377 {
378  if (lowVoltage < 5)
379  {
380  LOGDIAG3("Not a valid lower voltage limit. Must be greater than 5V \n");
381  return -1;
382  }
383 
384  int lowVoltageRaw=lowVoltage*10;
385  int overVoltageRaw=overVoltage*10;
386 
387  char buf[32];
388 
389  char cmd[32];
390  char res[32];
391  sprintf(cmd,"^UVL %d_^OVL %d\r", lowVoltageRaw, overVoltageRaw);
392  int nBytes = strlen(cmd);
393 
394  sendCommand(m_fd, (byte_t *)cmd, nBytes, m_ntimeout);
395  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
396  // check +/-
397  if (buf[0] =='-')
398  {
399  LOGERROR("setSpeedRaw(vec) command failed\n");
400  return -1;
401  }
402  recvResponse(m_fd,(byte_t *)res, m_ntimeout);
403  // check +/-
404  if (buf[0] =='-')
405  {
406  LOGERROR("setSpeedRaw(vec) command failed\n");
407  return -1;
408  }
409 
410  return 0;
411 }
int MotRoboteqSmall::stop ( int  motID)
virtual

Function stops motor specified.

Needs to be passed: Motor ID (1 or 2).

Implements rnr::Mot.

Definition at line 232 of file MotRoboteqSmall.cxx.

Referenced by testRoboteqSmallSanity().

233 {
234  setSpeedRaw(motID, 0);
235 }

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