peripherals  1.4.2
RoadNarrows Robotics Hardware Peripherals Package
Mot.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Peripherals
4 //
5 // Library: libmot
6 //
7 // File: Mot.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2013-04-02 15:23:46 -0600 (Tue, 02 Apr 2013) $
12  * $Rev: 2806 $
13  *
14  * \brief Common Motor Controller Interface.
15  *
16  * \author: Robin Knight (robin.knight@roadnarrows.com)
17  * \author: Daniel Packard (daniel@roadnarrows.com)
18  * \author: Jessica Trujillo (jessica@roadnarrows.com)
19  * \author: Maurice Woods III (maurice@roadnarrows.com)
20  *
21  * \copyright
22  * \h_copy 2012-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 // Permission is hereby granted, without written agreement and without
27 // license or royalty fees, to use, copy, modify, and distribute this
28 // software and its documentation for any purpose, provided that
29 // (1) The above copyright notice and the following two paragraphs
30 // appear in all copies of the source code and (2) redistributions
31 // including binaries reproduces these notices in the supporting
32 // documentation. Substantial modifications to this software may be
33 // copyrighted by their authors and need not follow the licensing terms
34 // described here, provided that the new terms are clearly indicated in
35 // all files where they apply.
36 //
37 // IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
38 // OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
39 // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
40 // DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
41 // EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
42 // THE POSSIBILITY OF SUCH DAMAGE.
43 //
44 // THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
45 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
46 // FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
47 // "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
48 // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
49 //
50 ////////////////////////////////////////////////////////////////////////////////
51 #ifndef _MOT_H
52 #define _MOT_H
53 
54 #define DEF_DEC -1
55 
56 #include <vector>
57 #include <string>
58 #include "rnr/rnrconfig.h"
59 #include "rnr/units.h"
60 
61 namespace rnr
62 {
63  class Mot
64  {
65  public:
67  {
68  int m_nMotID;
69  float m_fVal;
70  };
71 
72  struct IDIntTupple
73  {
74  int m_nMotID;
75  int m_nVal;
76  };
77 
78  typedef std::vector <IDFloatTupple> VecSpeedTupples;
79  typedef std::vector <IDIntTupple> VecSpeedRawTupples;
80  typedef std::vector <int> VecMotID;
81 
82  Mot()
83  {
84  m_fMaxSpeed = 0;
85  m_fMinSpeed = 0;
86  m_fSpeedStepSize = 0;
87  m_fMaxBrake = 0;
88  m_fMinBrake = 0;
89  m_fBrakeStepSize = 0;
90  }
91 
92  Mot(float maxSpeed, float minSpeed, float speedStepSize, float maxBrake, float minBrake, float brakeStepSize)
93  {
94  m_fMaxSpeed = maxSpeed;
95  m_fMinSpeed = minSpeed;
96  m_fSpeedStepSize = speedStepSize;
97  m_fMaxBrake = maxBrake;
98  m_fMinBrake = minBrake;
99  m_fBrakeStepSize = brakeStepSize;
100  }
101 
102  virtual ~Mot()
103  {
104  }
105 
106  /*!
107  * \brief Function opens serial communication with motor controller device
108  *
109  * Uses SerDevOpen to open serial connection with device (devName)
110  * Returns: File descriptor >=0 on success, -1 on fail.
111  */
112  virtual int open(const std::string &devName, int baudRate)=0;
113 
114  /*!
115  * \brief Function closes serial communication with motor controller device
116  *
117  * Uses SerDevClose to close serial connection.
118  * Returns: 0 on success, -1 on fail.
119  */
120  virtual int close()=0;
121 
122  /*!
123  * \brief Function sends commands to the motor controller and receives
124  * responses from the motor controller.
125  *
126  * Function uses SerDevWrite (libserial) to send commands over serial to
127  * the motor controllers, and uses recvResponse to receive echoed command
128  * responses as well as acknowledgements and query responses.
129  *
130  * Returns:
131  */
132  //virtual int sendCommand(int fd, byte_t *buf, int nBytes, int timeout)=0;
133 
134  /*!
135  * \brief Function is responsible for retrieving responses from motor
136  * controllers after a command has been sent.
137  *
138  * Returns: nBytes (number of bytes sent in response) on success
139  */
140  //virtual int getResponse(int fd, byte_t *buf, int timeout)=0;
141 
142  /*!
143  * \brief Function checks for valid motor ID inputs.
144  *
145  * Returns: 0 on success, -1 on fail.
146  */
147  virtual bool motIDIsValid(int motID)=0;
148 
149  /*!
150  * \brief
151  *
152  * Description
153  * \param id des
154  * \param [out] minSpeed des
155  *
156  * \return
157  */
158  //virtual int getMinSpeedLimit()=0;
159 
160  /*!
161  * \brief
162  *
163  * Description
164  * \param id des
165  * \param [out] minSpeed desmotSpeeds
166  *
167  * \return
168  */
169  //virtual int getMaxSpeedLimit()=0;
170 
171  /*!motSpeeds
172  * \brief
173  *
174  */
175  //virtual int setSpeedLimit(float &minSpeed, float &maxSpeed, float &stepSize,
176  //units_t units=normalized)=0;
177 
178  /*!
179 
180  * \brief
181  *
182  */
183  //virtual int getSpeed(int motID, units_t units=UnitsNorm)=0;
184 
185  /*!
186  * \brief Function retrieves the speed of a specific motor.
187  *
188  * Raw speed will be given.
189  *
190  *Needs to be passed: Motor ID (1 or 2)
191  *
192  * Returns: 0 on success, -1 upon failure.
193  */
194  //virtual int getSpeed(VecSpeed vecSpeedTupple, units_t units=UnitsNorm)=0;
195 
196  /*!
197  * \brief Function updates the speed of a single motor.
198  *
199  * Needs to be passed: A speed (-1 <= speed <= 1),
200  * and a motor id (0 = left, 1 = right)
201  * Returns: 0 on Success, -1 on incorrect speed, -2 on serial write fail.
202  */
203  virtual int setSpeed(int motID, float speed, units_t units=units_norm)=0;
204 
205  /*!
206  * \brief Function updates the speed of all motors simultaneously but
207  * individually.
208  *
209  * Function uses a vector to consturct a string of commands which will then be
210  * sent to multiple motors.
211  *
212  * Needs to be passed: motSpeeds vetor which includes a Motor ID (1 or 2) and
213  * a value between or equal to -1 and 1 for speed.
214  *
215  */
216  virtual int setSpeed(VecSpeedTupples vecSpeedTupple, units_t units=units_norm)=0;
217 
218  /*!
219  * \brief Function stops motor specified.
220  *
221  * Needs to be passed: Motor ID (1 or 2).
222  *
223  */
224  virtual int stop(int motID)=0;
225 
226  /*!
227  * \brief Function simultaneously halts motor rotation for all motors by
228  * setting speeds to zero.
229  *
230  * Needs to be passed:
231  *
232  */
233  //virtual int stop(VecMotID vecMotID, units_t units=UnitsNorm)=0;
234 
235  /*!
236  * \brief Function simultaneously halts motor rotation for all motors and locks
237  * the motor controller. No further commands can be given until EStop Release
238  * function has been passed.
239  *
240  */
241  virtual int eStop()=0;
242 
243  /*!
244  * \brief Function releases emergency stop condition and allows normal ops.
245  *
246  */
247  virtual int eStopRelease()=0;
248 
249 
250  /*!
251  * \brief Function determines if a motor controller can monitor current.
252  *
253  * If feature is not defined by the user, the controller will not monitor
254  * current.
255  */
256  //virtual bool hasFeatCurrent()=0;
257 
258  /*!
259  * \brief Function obtains current limit vaules from motor controller.
260  *
261  */
262  virtual int getCurrentLimits()=0;
263 
264  /*!alim
265  * \brief Function sets minimum and maximum limits for current.
266  */
267  virtual int setCurrentLimits(int motID, int current, units_t units=units_amp)=0;
268 
269  /*!
270  * \brief Function retrieves value for current load on a single motor.
271  *
272  */
273  virtual int getCurrent(int motID, units_t units=units_amp)=0;
274 
275  /*!
276  * \brief Function retrieves value for current load on a single motor.
277  *
278  */
279  //virtual int getCurrent(vec)=0;
280 
281  /*!
282  * \brief Function sets value for current supplied to a single motor.
283  *
284  */
285  //virtual int setCurrent(int motID, float current, units_t units=units_norm)=0;
286 
287  /*!
288  * \brief Function sets value for current supplied to a single motor.
289  *
290  */
291  //virtual int setCurrent(vec)=0;
292 
293  /*!
294  * \brief Function determines is a motor controller can monitor voltage.
295  *
296  * If feature is not defined by the user, the controller will not monitor
297  * voltage.
298  */
299  //virtual bool hasFeatVoltage()=0;
300 
301  /*!
302  * \brief Function retrieves voltage limits from motor controller.
303  *
304  *
305  */
306  virtual int getVoltageLimits()=0;
307 
308  /*!
309  * \brief Function sets the minimum and maximum limits for applied voltage
310  * for all motors.
311  *
312  * Needs to be passed: Low Voltage limit (>=5) and a Over Voltage limit (>=29).
313  *
314  */
315  virtual int setVoltageLimits(int lowVoltage, int overVoltage)=0;
316 
317  /*!
318  * \brief Function retrieves value for voltage applied to a single motor.
319  *
320  */
321  virtual int getVoltage()=0;
322 
323  /*!
324  * \brief Function retrieves value for voltage applied to a single motor.
325  *
326  */
327  //virtual int getVoltage(vec)=0;
328 
329  /*!
330  * \brief Function sets voltage value for an indivifual motor.
331  */
332  //virtual int setVoltage(int motID, float voltage)=0;
333 
334  /*!
335  * \brief Function sets voltage value for an individual motor.
336  */
337  //virtual int setVoltage(vec)=0;
338 
339  /*!
340  * \breif Function determines if a motor controller can monitor torque.
341  *
342  * If feature is not defined by the user, the controller will not monitor
343  * torque.
344  */
345  //virtual bool hasFeatTorque()=0
346 
347  /*!
348  * \brief Function retrieves value for torque output for a single motor.
349  *
350  */
351  //virtual int getTorqueLimit(int id, float torque)=0;
352 
353  /*!
354  * \brief Function sets minimum and maximum limits for motor torque.
355  *
356  */
357  //virtual int setTorqueLimit(float torque )=0;
358 
359  /*!
360  * \ brief Function retrives tourque values from an individual motor.
361  *
362  */
363  //virtual int getTorque(int motID, float torque)=0;
364 
365  /*!
366  * \ brief Function retrives tourque values from an individual motor.
367  *
368  */
369  //virtual int getTorque(vec)=0;
370 
371  /*!
372  * \brief Function sets the torque value for an individual motor.
373  *
374  * Higher torque values give the motor more turning strength.
375  */
376  //virtual int setTorque(int motID, float torque)=0;
377 
378  /*!
379  * \brief Function sets the torque value for an individual motor.
380  *
381  * Higher torque values give the motor more turning strength.
382  */
383  //virtual int setTorque(vec)=0;
384 
385  /*!
386  * \brief Function sets the acceleration rate for motors.
387  *
388  * Values represent 'slope' of the velocity profile when motor speeds are
389  * changed. In the case of deceleration, this is analogous to the
390  * difference between coasting to a stop (high argument values) and
391  * stopping abruptly (low argument values).
392  */
393  //virtual bool hasFeatSpeedProfile()=0;
394 
395  /*!
396  * \brief Function sets the acceleration rate for motors.
397  *
398  * Values represent 'slope' of the velocity profile when motor speeds are
399  * changed. In the case of deceleration, this is analogous to the
400  * difference between coasting to a stop (high argument values) and
401  * stopping abruptly (low argument values).
402  */
403  virtual int setSpeedProfile(int motID, int accel, int decel=DEF_DEC)=0;
404 
405  /*!
406  * \brief Function sets the acce1 leration rate for motors.
407  *
408  * Values represent 'slope' of the velocity profile when motor speeds are
409  * changed. In the case of deceleration, this is analogous to the
410  * difference between coasting to a stop (high argument values) and
411  * stopping abruptly (low argument values).
412  */
413  //virtual int setSpeedProfile(vector<float> vecParams)=0;
414 
415  /*!
416  * \brief
417  *
418  *
419  */
420  //virtual bool hasFeatPositionProfile()=0;
421 
422  /*!
423  * \brief
424  *
425  *
426  */
427  //virtual int setPositionProfile(vector<float> vecParams)=0;
428 
429  protected:
430  float m_fMaxSpeed;
431  float m_fMinSpeed;
432  float m_fSpeedStepSize;
433  float m_fMaxBrake;
434  float m_fMinBrake;
435  float m_fBrakeStepSize;
436 
437  };
438 }
439 #endif
virtual int getVoltageLimits()=0
Function retrieves value for current load on a single motor.
virtual int open(const std::string &devName, int baudRate)=0
Function opens serial communication with motor controller device.
virtual int stop(int motID)=0
Function stops motor specified.
virtual int getVoltage()=0
Function retrieves value for voltage applied to a single motor.
virtual int getCurrentLimits()=0
Function determines if a motor controller can monitor current.
virtual int setSpeedProfile(int motID, int accel, int decel=-1)=0
Function retrieves value for voltage applied to a single motor.
virtual int eStopRelease()=0
Function releases emergency stop condition and allows normal ops.
Definition: Mot.h:63
virtual int setVoltageLimits(int lowVoltage, int overVoltage)=0
Function sets the minimum and maximum limits for applied voltage for all motors.
virtual int setSpeed(int motID, float speed, units_t units=units_norm)=0
Description.
virtual int setCurrentLimits(int motID, int current, units_t units=units_amp)=0
Function sets minimum and maximum limits for current.
virtual int eStop()=0
Function simultaneously halts motor rotation for all motors by setting speeds to zero.
virtual int getCurrent(int motID, units_t units=units_amp)=0
Function retrieves value for current load on a single motor.
virtual bool motIDIsValid(int motID)=0
Function sends commands to the motor controller and receives responses from the motor controller...
float m_fMaxSpeed
Function sets the acce1 leration rate for motors.
Definition: Mot.h:430
virtual int close()=0
Function closes serial communication with motor controller device.
RoadNarrows Robotics standard namespace.
Definition: HID.h:65