Fawkes API  Fawkes Development Version
qa_robot.cpp
1 
2 /***************************************************************************
3  * qa_robot.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 
28 #include <plugins/openrave/types.h>
29 #include <plugins/openrave/environment.h>
30 #include <plugins/openrave/robot.h>
31 #include <plugins/openrave/manipulators/katana6M180.h>
32 #include <logging/console.h>
33 #include <cstdio>
34 #include <iostream>
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  {
48  s << "(" << i << ")" << v[i] << " ";
49  //printf("## %u:)%f \n", i, v[i]);
50  }
51  printf("%s \n", s.str().c_str());
52 }
53 
54 int
55 main(int argc, char **argv)
56 {
57  printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
58 
59  string robotFile = SRCDIR"/../manipulators/katana.robot.xml";
60 
61  ConsoleLogger* cl = new ConsoleLogger();
62 
64  OpenRaveRobotPtr robot( new OpenRaveRobot(cl) );
66 
67  env->create();
68 
69  try {
70  robot->load(robotFile, env);
71  } catch (Exception &e) {
72  cl->log_error("qa_robot", "error:%s", e.what());
73  return 0;
74  }
75 
76  // configure manip
77  manip->add_motor(0,0);
78  manip->add_motor(1,1);
79  manip->add_motor(2,2);
80  manip->add_motor(4,3);
81  manip->add_motor(5,4);
82  robot->set_manipulator(manip);
83 
84  env->add_robot(robot);
85  robot->set_ready();
86  env->lock();
87 
88 
89  vector<float> val, v;
90  val.push_back(0.1);
91  val.push_back(0.2);
92  val.push_back(0.3);
93  val.push_back(0.4);
94  val.push_back(0.5);
95 
96  manip->set_angles_device(val);
97  manip->get_angles(v);
98  printVector(v);
99  manip->get_angles_device(v);
100  printVector(v);
101 
102 
103  env->start_viewer();
104 
105  //print angles taken from OpenRAVE Model (can be modified in GUI)
106  while(1) {
107  robot->update_manipulator();
108  manip->get_angles(v);
109  printVector(v);
110  manip->get_angles_device(v);
111  printVector(v);
112  usleep(1000*500);
113  }
114 
115 
116  env->destroy();
117 
118  return 0;
119 }
120 
121 
122 /// @endcond
Class containing information about all katana6M180 motors.
Definition: katana6M180.h:33
Interface for logging to stderr.
Definition: console.h:36
Fawkes library namespace.
STL namespace.
virtual const char * what() const
Get primary string.
Definition: exception.cpp:661
virtual void log_error(const char *component, const char *format,...)
Log error message.
Definition: console.cpp:167
OpenRAVE Robot class.
Definition: robot.h:39
Base class for exceptions in Fawkes.
Definition: exception.h:36
OpenRaveEnvironment class.
Definition: environment.h:45