Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeMotor.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelasp
4 //
5 // Library: liblaelaps
6 //
7 // File: laeMotor.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-03-07 17:57:47 -0700 (Mon, 07 Mar 2016) $
12  * $Rev: 4345 $
13  *
14  * \brief Laelaps motors, encoder, and controllers hardware abstraction
15  * interfaces.
16  *
17  * \author Robin Knight (robin.knight@roadnarrows.com)
18  *
19  * \par Copyright
20  * \h_copy 2015-2017. RoadNarrows LLC.\n
21  * http://www.roadnarrows.com\n
22  * All Rights Reserved
23  */
24 /*
25  * @EulaBegin@
26  *
27  * Unless otherwise stated explicitly, all materials contained are copyrighted
28  * and may not be used without RoadNarrows LLC's written consent,
29  * except as provided in these terms and conditions or in the copyright
30  * notice (documents and software) or other proprietary notice provided with
31  * the relevant materials.
32  *
33  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
34  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
35  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
36  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
37  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
38  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
41  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
42  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
43  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
44  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
45  *
46  * @EulaEnd@
47  */
48 ////////////////////////////////////////////////////////////////////////////////
49 
50 #ifndef _LAE_MOTOR_H
51 #define _LAE_MOTOR_H
52 
53 #include <sys/types.h>
54 
55 #include <string>
56 
57 #include "rnr/rnrconfig.h"
58 #include "rnr/log.h"
59 
60 #include "Laelaps/RoboClaw.h"
61 
62 #include "Laelaps/laelaps.h"
63 
64 namespace laelaps
65 {
66  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67 
68  /*!
69  * \ingroup lae_spec
70  *
71  * \defgroup lae_motor Laelaps Motors
72  *
73  * \h_laelaps motors, encoders, and controllers.
74  *
75  * The \h_laelaps currently uses Ion Motion Control's RoboClaw 30A motor
76  * controllers. The motors are...
77  *
78  * The \h_laelaps two motor controllers control two motors each. The motors
79  * are attached to the internal side of the body and drive independent
80  * wheel-tire assemblies. The front controller controls the left-front and
81  * right-front wheels, while the back controller controls the left-rear and
82  * right-rear wheels.
83  *
84  * The left side motors are mounted to the body such that they have normal
85  * sense of rotation. The right side motors have reverse sense.
86  * \{
87  */
88 
89  //
90  // Controller/Powertrain/motor string keys.
91  //
92  static const char* const LaeKeyFront = "front"; ///< front
93  static const char* const LaeKeyRear = "rear"; ///< rear
94  static const char* const LaeKeyLeftFront = "left_front"; ///< left front
95  static const char* const LaeKeyRightFront = "right_front"; ///< right front
96  static const char* const LaeKeyLeftRear = "left_rear"; ///< left rear
97  static const char* const LaeKeyRightRear = "right_rear"; ///< right rear
98 
99  //
100  // Absolute powertrain/motor ids.
101  //
102  static const int LaeMotorIdNone = -1; ///< no motor id
103  static const int LaeMotorIdLF = 0; ///< left front
104  static const int LaeMotorIdRF = 1; ///< right front
105  static const int LaeMotorIdLR = 2; ///< left rear
106  static const int LaeMotorIdRR = 3; ///< right rear
107  static const int LaeMotorsNumOf = 4; ///< number of motors
108 
109  //
110  // Motor controllers (2 motors/controller).
111  //
112  static const int LaeMotorCtlrIdNone = -1; ///< no motor controller id
113  static const int LaeMotorCtlrIdFront = 0; ///< front motor controller
114  static const int LaeMotorCtlrIdRear = 1; ///< rear motor controller
115  static const int LaeNumMotorCtlrs = 2; ///< number of motor controllers
116 
117  //
118  // Motor controller communication channel addresses.
119  //
120  static const byte_t LaeMotorCtlrAddrFront = motor::roboclaw::AddrMin;
121  ///< front motor controller address
122  static const byte_t LaeMotorCtlrAddrRear = motor::roboclaw::AddrMin + 1;
123  ///< rear motor controller address
124 
125  //
126  // Motor control motor relative indices.
127  //
128  static const int LaeMotorLeft = motor::roboclaw::Motor1; ///< left motors
129  static const int LaeMotorRight = motor::roboclaw::Motor2; ///< right motors
130  static const int LaeNumMotorsPerCtlr = motor::roboclaw::NumMotors;
131  ///< number of motors/controller
132 
133  //
134  // Motor sense of rotation.
135  //
136  static const int LaeMotorDirNormal = motor::roboclaw::MotorDirNormal;
137  ///< normal
138  static const int LaeMotorDirReverse = motor::roboclaw::MotorDirReverse;
139  ///< reverse
140  //
141  // Motor alarms (derived from motor controller status).
142  //
143  static const int LaeMotorAlarmNone = 0x00; ///< no alarms
144  static const int LaeMotorAlarmCurrent = 0x01; ///< under/over current
145  static const int LaeMotorAlarmVoltage = 0x02; ///< under/over voltage
146  static const int LaeMotorAlarmEStop = 0x04; ///< emergency stopped
147  static const int LaeMotorAlarmTemp = 0x08; ///< over temperature
148  static const int LaeMotorAlarmFault = 0x10; ///< motor drive fault
149 
150  //
151  // Motor warnings (derived from motor controller status).
152  //
153  static const int LaeMotorWarnNone = 0x00; ///< no warnings
154  static const int LaeMotorWarnCurrent = 0x01; ///< over current
155  static const int LaeMotorWarnTemp = 0x02; ///< over temperature
156  static const int LaeMotorWarnVoltage = 0x04; ///< under/over voltage
157 
158  //
159  // Motor properties.
160  //
161  // For v2.0 platforms, there is 1 battery circuit with a maximum of 10 amps.
162  // For v2.1+ platforms, there are 2 battery circuits with a max of 20 amps.
163  //
164  static const int LaeQuadPulsesPerRev = 64; ///< pulses/motor revolution
165  static const double LaeMotorGearRatio = 30.0; ///< gear ratio
166  static const double LaeMotorRatedMaxRpm = 350.0; ///< max output shaft rpm
167  static const double LaeMotorStallTorque = 0.776771;
168  ///< stall torque (N-m) @5A
169  static const double LaeMotorRatedAmps = 5.0; ///< motor rated max amps.
170  static const double LaeMotorMaxAmps = 30.0; ///< max amp limit/motor
171  static const double LaeMotorMaxAmps_2_0 = 2.5; ///< max amp limit/motor
172  static const double LaeMotorMaxAmps_2_1 = 5.0; ///< max amp limit/motor
173 
174 
175  // ---------------------------------------------------------------------------
176  // LaeMotorCtlrChipSelect Class
177  // ---------------------------------------------------------------------------
178 
179  /*!
180  * \brief RoboClaw motor controller chip select class.
181  *
182  * The RoboClawChipSelect class instance is used to select the motor
183  * controller, given its address.
184  *
185  * For Laelaps, this is accomplished through a digital GPIO pin.
186  *
187  * With the new RoboClaw firmware, chip select is no longer necessary.
188  * This class is deprecated.
189  */
191  {
192  public:
193  // motor controller chip select values
195  ///< motor controller address associated with high signal
197  ///< motor controller address associated with low signal
198 
199  /*!
200  * \brief Default constructor.
201  */
203 
204  /*!
205  * \brief Destructor.
206  */
207  virtual ~LaeMotorCtlrChipSelect();
208 
209  /*!
210  * \brief Open GPIO pin interface.
211  *
212  * \param pinGpio The sysfs exported GPIO number.
213  *
214  * \copydoc doc_return_std
215  */
216  virtual int open(int pinGpio);
217 
218  /*!
219  * \brief Close GPIO pin interface.
220  *
221  * \copydoc doc_return_std
222  */
223  virtual int close();
224 
225  /*!
226  * \brief Test if connection is open.
227  *
228  * \return Returns true or false.
229  */
230  virtual bool isOpen()
231  {
232  return m_fdGpio >= 0;
233  }
234 
235  /*!
236  * \brief Motor controller select function.
237  *
238  * The motor controllers are on a multi-drop serial bus. Serial does not
239  * support multiple tx drivers on the same bus. Since there are two motor
240  * controllers, each with a transmit line (odroid receive), the select
241  * function disconnects one tx while connects the target tx.
242  *
243  * \param fd Open serial file descriptor.
244  * \param addrSel Target motor controller to be selected. Controllers
245  * are identified by their address.
246  */
247  virtual void select(int fd, byte_t addrSel);
248 
249  protected:
250  int m_pinGpio;
251  int m_fdGpio;
252  };
253 
254 } // namespace laelaps
255 
256 #endif // _LAE_MOTOR_H
static const int LaeMotorIdRR
right rear
Definition: laeMotor.h:106
static const double LaeMotorRatedMaxRpm
max output shaft rpm
Definition: laeMotor.h:166
static const int LaeQuadPulsesPerRev
pulses/motor revolution
Definition: laeMotor.h:164
static const double LaeMotorMaxAmps
max amp limit/motor
Definition: laeMotor.h:170
static const int LaeMotorCtlrIdRear
rear motor controller
Definition: laeMotor.h:114
static const int LaeMotorWarnVoltage
under/over voltage
Definition: laeMotor.h:156
static const int LaeMotorDirNormal
normal
Definition: laeMotor.h:136
static const double LaeMotorMaxAmps_2_0
max amp limit/motor
Definition: laeMotor.h:171
static const int LaeMotorsNumOf
number of motors
Definition: laeMotor.h:107
static const int LaeMotorIdNone
no motor id
Definition: laeMotor.h:102
static const char *const LaeKeyLeftRear
left rear
Definition: laeMotor.h:96
RoboClaw motor controller chip select class.
Definition: laeMotor.h:190
static const char *const LaeKeyRightFront
right front
Definition: laeMotor.h:95
RoboClaw motor controller class interface.
static const char *const LaeKeyRear
rear
Definition: laeMotor.h:93
static const char *const LaeKeyFront
front
Definition: laeMotor.h:92
static const int LaeMotorAlarmEStop
emergency stopped
Definition: laeMotor.h:146
static const int LaeMotorLeft
left motors
Definition: laeMotor.h:128
virtual void select(int fd, byte_t addrSel)
Motor controller select function.
Definition: laeMotor.cxx:113
static const double LaeMotorStallTorque
stall torque (N-m) @5A
Definition: laeMotor.h:167
static const int LaeMotorIdRF
right front
Definition: laeMotor.h:104
static const int LaeMotorIdLR
left rear
Definition: laeMotor.h:105
RoboClaw motor controller chip select class.
Definition: RoboClaw.h:444
static const char *const LaeKeyRightRear
right rear
Definition: laeMotor.h:97
virtual int close()
Close GPIO pin interface.
Definition: laeMotor.cxx:98
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
static const byte_t LaeMotorCtlrAddrRear
rear motor controller address
Definition: laeMotor.h:122
static const int LaeMotorDirReverse
reverse
Definition: laeMotor.h:138
static const int LaeMotorAlarmCurrent
under/over current
Definition: laeMotor.h:144
static const byte_t LaeMotorCtlrAddrFront
front motor controller address
Definition: laeMotor.h:120
static const byte_t LaeMotorCtlrCsHigh
motor controller address associated with high signal
Definition: laeMotor.h:194
static const int LaeMotorIdLF
left front
Definition: laeMotor.h:103
static const int LaeMotorWarnNone
no warnings
Definition: laeMotor.h:153
static const double LaeMotorRatedAmps
motor rated max amps.
Definition: laeMotor.h:169
static const int LaeMotorCtlrIdNone
no motor controller id
Definition: laeMotor.h:112
static const double LaeMotorGearRatio
gear ratio
Definition: laeMotor.h:165
virtual ~LaeMotorCtlrChipSelect()
Destructor.
Definition: laeMotor.cxx:78
static const int LaeNumMotorCtlrs
number of motor controllers
Definition: laeMotor.h:115
static const int LaeMotorAlarmTemp
over temperature
Definition: laeMotor.h:147
LaeMotorCtlrChipSelect()
Default constructor.
Definition: laeMotor.cxx:72
static const int LaeMotorAlarmNone
no alarms
Definition: laeMotor.h:143
static const int LaeMotorCtlrIdFront
front motor controller
Definition: laeMotor.h:113
static const int LaeMotorRight
right motors
Definition: laeMotor.h:129
virtual int open(int pinGpio)
Open GPIO pin interface.
Definition: laeMotor.cxx:83
static const int LaeMotorAlarmVoltage
under/over voltage
Definition: laeMotor.h:145
virtual bool isOpen()
Test if connection is open.
Definition: laeMotor.h:230
static const double LaeMotorMaxAmps_2_1
max amp limit/motor
Definition: laeMotor.h:172
static const char *const LaeKeyLeftFront
left front
Definition: laeMotor.h:94
static const byte_t LaeMotorCtlrCsLow
motor controller address associated with low signal
Definition: laeMotor.h:196
static const int LaeNumMotorsPerCtlr
number of motors/controller
Definition: laeMotor.h:130
static const int LaeMotorWarnCurrent
over current
Definition: laeMotor.h:154
static const int LaeMotorWarnTemp
over temperature
Definition: laeMotor.h:155
Top-level package include file.
static const int LaeMotorAlarmFault
motor drive fault
Definition: laeMotor.h:148