Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
utRobot.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelaps
4 //
5 // Program: utRobot
6 //
7 // File: utRobot.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-02-01 15:14:45 -0700 (Mon, 01 Feb 2016) $
12  * $Rev: 4289 $
13  *
14  * \brief Unit test liblaelaps robot class.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #include <unistd.h>
50 #include <string.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <stdarg.h>
54 
55 #include <iostream>
56 #include <fstream>
57 #include <string>
58 
59 #include "rnr/rnrconfig.h"
60 #include "rnr/log.h"
61 #include "rnr/opts.h"
62 #include "rnr/pkg.h"
63 
64 #include "Laelaps/laelaps.h"
65 #include "Laelaps/laeDesc.h"
66 #include "Laelaps/laeXmlCfg.h"
67 #include "Laelaps/laeRobot.h"
68 
69 #include "version.h"
70 
71 using namespace std;
72 using namespace laelaps;
73 
74 /*!
75  * \ingroup apps
76  * \defgroup unittest utRobot
77  * \{
78  */
79 
80 #define APP_EC_OK 0 ///< success exit code
81 #define APP_EC_ARGS 2 ///< command-line options/arguments error exit code
82 #define APP_EC_EXEC 4 ///< execution exit code
83 
84 static char *Argv0; ///< the command
85 
86 /*!
87  * \brief Program information.
88  */
89 static OptsPgmInfo_T PgmInfo =
90 {
91  // usage_args
92  "<FILE>",
93 
94  // synopsis
95  "Unit test liblaelaps LaeRobot class.",
96 
97  // long_desc =
98  "The %P command unit tests the liblaelap LaeRobot class basic operation.",
99 
100  // diagnostics
101  NULL
102 };
103 
104 /*!
105  * \brief Command line options information.
106  */
107 static OptsInfo_T OptsInfo[] =
108 {
109  {NULL, }
110 };
111 
112 /*!
113  * \brief Main initialization.
114  *
115  * \param argc Command-line argument count.
116  * \param argv Command-line argument list.
117  *
118  * \par Exits:
119  * Program terminates on conversion error.
120  */
121 static void mainInit(int argc, char *argv[])
122 {
123  // name of this process
124  Argv0 = basename(argv[0]);
125 
126  // parse input options
127  argv = OptsGet(Argv0, &PkgInfo, &PgmInfo, OptsInfo, true, &argc, argv);
128 }
129 
130 /*!
131  * \brief Main.
132  *
133  * \param argc Command-line argument count.
134  * \param argv Command-line argument list.
135  *
136  * \return Returns 0 on succes, non-zero on failure.
137  */
138 int main(int argc, char* argv[])
139 {
140  const char* const CfgFile = "/prj/pkg/Laelaps/share/etc/laelaps/laelaps.conf";
141 
142  LaeRobot *pRobot;
143  LaeXmlCfg xml;
144  uint_t sec;
145  int rc;
146 
147  mainInit(argc, argv);
148 
149  printf("Creating robot.\n");
150  pRobot = new LaeRobot;
151  printf("Created.\n");
152 
153  sec = 1;
154  printf(" sleeping %u seconds ...", sec);
155  sleep(sec);
156  printf("\n");
157 
158  LaeDesc &desc = pRobot->getLaelapsDesc();
159 
160  printf("Parsing robot description.\n");
161  if( (rc = xml.loadFile(desc, CfgFile)) == LAE_OK )
162  {
163  rc = desc.markAsDescribed();
164  }
165 
166  if( rc != LAE_OK )
167  {
168  printf("Failed to load/parse description.\n");
169  return APP_EC_EXEC;
170  }
171 
172  printf("Connecting robot.\n");
173  if( (rc = pRobot->connect()) == LAE_OK )
174  {
175  printf("Connected\n");
176  }
177  else
178  {
179  printf("Failed to connect.\n");
180  }
181 
182  sec = 5;
183  printf(" sleeping %u seconds ...", sec);
184  sleep(sec);
185  printf("\n");
186 
187  if( pRobot->isConnected() )
188  {
189  printf("Disconnecting robot.\n");
190  if( (rc = pRobot->disconnect()) == LAE_OK )
191  {
192  printf("Disconnected\n");
193  }
194  else
195  {
196  printf("Failed to disconnect.\n");
197  }
198  }
199 
200  printf("Deleting robot.\n");
201  delete pRobot;
202  printf("Deleted.\n");
203 
204  sec = 1;
205  printf(" sleeping %u seconds ...", sec);
206  sleep(sec);
207  printf("\n");
208 
209  return APP_EC_OK;
210 }
211 
212 /*!
213  * \}
214  */
static char * Argv0
the command
Definition: utRobot.cxx:84
static void mainInit(int argc, char *argv[])
Main initialization.
Definition: utRobot.cxx:121
Laelaps robotic mobile platform full description class.
Definition: laeDesc.h:451
int connect()
Connect to <b><i>Laelaps</i></b>.
Definition: laeRobot.cxx:193
virtual int loadFile(const std::string &strXmlFileName=LaeEtcCfg)
Load XML file into DOM.
LaeDesc & getLaelapsDesc()
Get the <b><i>Laelaps</i></b> product description.
Definition: laeRobot.cxx:746
#define APP_EC_OK
success exit code
Definition: utRobot.cxx:80
int disconnect()
Disconnect from <b><i>Laelaps</i></b>.
Definition: laeRobot.cxx:333
static OptsInfo_T OptsInfo[]
Command line options information.
Definition: utRobot.cxx:107
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
Laelaps robotic base mobile platform description class interface.
static const PkgInfo_T PkgInfo
Definition: version.h:45
int markAsDescribed()
Mark <b><i>Laelaps</i></b> hardware as fully described.
Definition: laeDesc.cxx:672
Package version information.
Laelasp Robot Class interface.
int main(int argc, char *argv[])
Main.
Definition: utRobot.cxx:138
#define APP_EC_EXEC
execution exit code
Definition: utRobot.cxx:82
<b><i>Laelaps</i></b> XML configuration class interface.
bool isConnected()
Test if connected to <b><i>Laelaps</i></b> hardware.
Definition: laeRobot.cxx:726
Laelaps robotic manipulator plus accesories class.
Definition: laeRobot.h:103
static OptsPgmInfo_T PgmInfo
Program information.
Definition: utRobot.cxx:89
Top-level package include file.
LaeXmlCfg <b><i>Laelaps</i></b> XML configuration class.
Definition: laeXmlCfg.h:71