peripherals  1.4.2
RoadNarrows Robotics Hardware Peripherals Package
ut-roboteq-small.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Peripherals
4 //
5 /*! \file
6  *
7  * $LastChangedDate: 2013-09-24 09:34:42 -0600 (Tue, 24 Sep 2013) $
8  * $Rev: 3323 $
9  *
10  * \ingroup periphs_ut
11  *
12  * \brief Unit test for libmot roboteq-small motor controller
13  *
14  * \author Daniel Packard (daniel@roadnarrows.com)
15  *
16  * \copyright
17  * \h_copy 2013-2017. RoadNarrows LLC.\n
18  * http://www.roadnarrows.com\n
19  * All Rights Reserved
20  */
21 //
22 // Redistribution and use in source and binary forms, with or without
23 // modification, are permitted provided that the following conditions are met:
24 //
25 // 1. Redistributions of source code must retain the above copyright notice,
26 // this list of conditions and the following disclaimer.
27 //
28 // 2. Redistributions in binary form must reproduce the above copyright notice,
29 // this list of conditions and the following disclaimer in the documentation
30 // and/or other materials provided with the distribution.
31 //
32 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
36 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 // POSSIBILITY OF SUCH DAMAGE.
42 //
43 // The views and conclusions contained in the software and documentation are
44 // those of the authors and should not be interpreted as representing official
45 // policies, either expressed or implied, of the FreeBSD Project.
46 
47 #include <iostream>
48 #include <string>
49 #include <vector>
50 
51 #include "rnr/rnrconfig.h"
52 #include "rnr/log.h"
54 
55 #include <gtest/gtest.h>
56 
57 using namespace rnr;
58 using namespace std;
59 
60 /*!
61  * \ingroup periphs_ut
62  * \defgroup periphs_ut_libmot_roboteq_s Roboteq Small Unit Tests
63  * \brief Fine-grained testing of Roboteq Small motor controller
64  * \{ST
65  */
66 
67 /*!
68  * \brief Sanity test Roboteq-small interface.
69  *
70  * \return Returns 0 if test succeeds, else returns 0.
71  */
73 {
74  return 0;
75 }
76 
77 
78 
79 TEST(RoboteqSmall, sanity)
80 {
81  EXPECT_TRUE( testRoboteqSmallSanity() == 0 );
82 }
83 
84 #ifndef JENKINS
85 
86 static int testRoboteqSmallOpenClose()
87 {
88  MotRoboteqSmall mot;
89  string devName="/dev/ttyACM0";
90  int baudRate=115200;
91  if(mot.open(devName, baudRate)!=0)
92  {
93  fprintf(stderr, "jnt failed to open\n");
94  return -1;
95  }
96 
97  if(mot.close()!=0)
98  {
99  fprintf(stderr, "jnt failed to close\n");
100  return -1;
101  }
102  return 0;
103 }
104 
105 TEST(RoboteqSmall, openClose)
106 {
107  EXPECT_TRUE(testRoboteqSmallOpenClose() == 0);
108 }
109 
110 static int testRoboteqSmallSetSpeed()
111 {
112  MotRoboteqSmall mot;
113  string devName="/dev/ttyACM0";
114  int baudRate=115200;
115  if(mot.open(devName, baudRate)!=0)
116  {
117  fprintf(stderr, "jnt failed to open\n");
118  return -1;
119  }
120 int i=0;
121 int j=100;
122 int h=j*2;
123 /* while (i <j)
124  {
125  mot.setSpeed(2,1);
126  mot.getCurrent(2);
127  usleep(10000);
128  i++;
129  }
130  mot.setSpeed(2,0);
131  while (i <h)
132  {
133  mot.setSpeed(1,1);
134  mot.getCurrent(1);
135  usleep(10000);
136  i++;
137  }
138  mot.setSpeed(1,0);
139 
140  if(mot.close()!=0)
141  {
142  fprintf(stderr, "jnt failed to close\n");
143  return -1;
144  }
145 */ return 0;
146 }
147 
148 TEST(RoboteqSmall, setSpeed)
149 {
150  EXPECT_TRUE(testRoboteqSmallSetSpeed() == 0);
151 }
152 
153 static int testRoboteqSmallSetSpeedVec()
154 {
155  MotRoboteqSmall mot;
156  string devName="/dev/ttyACM0";
157  int baudRate=115200;
158  if(mot.open(devName, baudRate)!=0)
159  {
160  fprintf(stderr, "jnt failed to open\n");
161  return -1;
162  }
163 
164  Mot::VecSpeedTupples motSpeeds;
165  Mot::IDFloatTupple tmp;
166 
167  mot.setVoltageLimits(6, 29);
168  mot.getVoltageLimits();
169  mot.getVoltage();
170 
171  mot.setCurrentLimits(1, 19);
172  mot.setCurrentLimits(2, 20);
173  mot.getCurrentLimits();
174 
175 //
176  tmp.m_nMotID=1;
177  tmp.m_fVal=0.5;
178  motSpeeds.push_back(tmp);
179 
180  tmp.m_nMotID=2;
181  tmp.m_fVal=0.2;
182  motSpeeds.push_back(tmp);
183 
184  mot.setSpeed(motSpeeds);
185  usleep(500000);
186 
187 //
188  mot.setSpeedProfile(1,2000);
189  mot.setSpeedProfile(2,2000);
190 
191  tmp.m_nMotID=1;
192  tmp.m_fVal=1;
193  motSpeeds.push_back(tmp);
194 
195  tmp.m_nMotID=2;
196  tmp.m_fVal=1;
197  motSpeeds.push_back(tmp);
198 
199  mot.setSpeed(motSpeeds);brakeStepSize
200  usleep(500000);
201 
202 //
203  tmp.m_nMotID=1;
204  tmp.m_fVal=1;
205  motSpeeds.push_back(tmp);
206 
207  tmp.m_nMotID=2;
208  tmp.m_fVal=1;
209  motSpeeds.push_back(tmp);
210 
211  mot.setSpeed(motSpeeds);
212  usleep(500000);
213 
214 //
215  tmp.m_nMotID=1;
216  tmp.m_fVal=1;
217  motSpeeds.push_back(tmp);
218 
219  tmp.m_nMotID=2;
220  tmp.m_fVal=1;
221  motSpeeds.push_back(tmp);
222 
223  mot.setSpeed(motSpeeds);
224  usleep(500000);
225 
226 //
227  tmp.m_nMotID=1;
228  tmp.m_fVal=1;
229  motSpeeds.push_back(tmp);
230 
231  tmp.m_nMotID=2;
232  tmp.m_fVal=1;
233  motSpeeds.push_back(tmp);
234 
235  mot.setSpeed(motSpeeds);
236  usleep(500000);
237 
238 //
239  tmp.m_nMotID=1;
240  tmp.m_fVal=1;
241  motSpeeds.push_back(tmp);
242 
243  tmp.m_nMotID=2;
244  tmp.m_fVal=1;
245  motSpeeds.push_back(tmp);
246 
247  mot.setSpeed(motSpeeds);
248  usleep(500000);
249 
250 //
251  mot.setSpeedProfile(1,20000);
252  mot.setSpeedProfile(2,20000);
253 
254  mot.stop(2);
255  mot.stop(1);
256 
257  if(mot.close()!=0)
258  {
259  //fprintf(stderr, "jnt failed to close\n");
260  return -1;
261  }
262 
263  return 0;
264 }
265 
266 
267 TEST(RoboteqSmall, setSpeedVec)
268 {
269  EXPECT_TRUE(testRoboteqSmallSetSpeedVec() == 0);
270 }
271 
272 
273 
274 // put tests that require human input here.
275 
276 #endif // JENKINS
277 
278 
279 /*!
280  * \}
281  */
int setVoltageLimits(int lowVoltage, int overVoltage)
Function sets the minimum and maximum limits for applied voltage for all motors.
static int testRoboteqSmallSanity()
Sanity test Roboteq-small interface.
int setSpeedProfile(int motID, int accel, int decel=DEF_DEC)
Function retrieves value for voltage applied to a single motor.
Common Human Interface Device Interface.
int setSpeed(int motID, float speed, units_t units=units_norm)
Description.
int setCurrentLimits(int motID, int current, units_t units=units_amp)
Function sets minimum and maximum limits for current.
int open(const std::string &devName, int baudRate)
Function opens serial communication with motor controller device.
int close()
Function closes serial communication with motor controller device.
int getVoltageLimits()
Function retrieves value for current load on a single motor.
RoadNarrows Robotics standard namespace.
Definition: HID.h:65
int getCurrentLimits()
Function determines if a motor controller can monitor current.
int stop(int motID)
Function stops motor specified.
int getVoltage()
Function retrieves value for voltage applied to a single motor.
TEST(Xbox360, XboxSanity)
Sanity test Xbox360 controller interface.