Fawkes API  Fawkes Development Version
qa_modules.cpp
1 
2 /***************************************************************************
3  * qa_modules.cpp - QA for OpenRAVE Environment class
4  *
5  * Created: Thu Sep 16 14:50:34 2010
6  * Copyright 2010 Bahram Maleki-Fard, AllemaniACs RoboCup Team
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 // Do not include in api reference
25 ///@cond QA
26 
27 #include <logging/console.h>
28 #include <openrave/openrave.h>
29 #include <plugins/openrave/environment.h>
30 #include <plugins/openrave/robot.h>
31 
32 #include <cstdio>
33 #include <iostream>
34 #include <list>
35 #include <sstream>
36 #include <vector>
37 
38 using namespace fawkes;
39 using namespace std;
40 
41 void
42 printVector(vector<float> &v)
43 {
44  stringstream s;
45  //printf("## size:%u \n", v.size());
46  for (unsigned int i = 0; i < v.size(); i++) {
47  s << "(" << i << ")" << v[i] << " ";
48  //printf("## %u:)%f \n", i, v[i]);
49  }
50  printf("%s \n", s.str().c_str());
51 }
52 
53 int
54 main(int argc, char **argv)
55 {
56  printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
57 
58  string robotFile = SRCDIR "/../manipulators/katana.robot.xml";
59 
60  ConsoleLogger *cl = new ConsoleLogger();
61 
62  OpenRaveRobotPtr robot(new OpenRaveRobot(cl));
64 
65  vector<OpenRAVE::RobotBasePtr> robots;
66  list<OpenRAVE::ModuleBasePtr> modules;
67 
68  env->create();
69 
70  env->get_env_ptr()->GetModules(modules);
71  env->get_env_ptr()->GetRobots(robots);
72  cl->log_debug("qa_modules", "Environment created");
73  cl->log_debug("qa_modules", "#modules:%u #robots:%u", modules.size(), robots.size());
74 
75  try {
76  robot->load(robotFile, env);
77  } catch (Exception &e) {
78  cl->log_error("qa_modules", "error:%s", e.what());
79  return 0;
80  }
81 
82  env->get_env_ptr()->GetModules(modules);
83  env->get_env_ptr()->GetRobots(robots);
84  cl->log_debug("qa_modules", "Robot loaded");
85  cl->log_debug("qa_modules", "#modules:%u #robots:%u", modules.size(), robots.size());
86 
87  env->add_robot(robot);
88  robot->set_ready();
89 
90  env->get_env_ptr()->GetModules(modules);
91  env->get_env_ptr()->GetRobots(robots);
92  cl->log_debug("qa_modules", "Robot initialized");
93  cl->log_debug("qa_modules", "#modules:%u #robots:%u", modules.size(), robots.size());
94 
95  robot = NULL;
96 
97  env->get_env_ptr()->GetModules(modules);
98  env->get_env_ptr()->GetRobots(robots);
99  cl->log_debug("qa_modules", "Robot Destroyed");
100  cl->log_debug("qa_modules", "#modules:%u #robots:%u", modules.size(), robots.size());
101 
102  env->destroy();
103 
104  return 0;
105 }
106 
107 /// @endcond
Interface for logging to stderr.
Definition: console.h:36
Fawkes library namespace.
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
Definition: console.cpp:154
virtual const char * what() const
Get primary string.
Definition: exception.cpp:639
virtual void log_error(const char *component, const char *format,...)
Log error message.
Definition: console.cpp:181
OpenRAVE Robot class.
Definition: robot.h:37
Base class for exceptions in Fawkes.
Definition: exception.h:35
OpenRaveEnvironment class.
Definition: environment.h:43
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:49