iCub-main
iCub_Sim.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4 * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
5 * Author: Paul Fitzpatrick, Vadim Tikhanoff, Martin Peniak
6 * email: paulfitz@alum.mit.edu, vadim.tikhanoff@iit.it, martin.peniak@plymouth.ac.uk
7 * website: www.robotcub.org
8 * Permission is granted to copy, distribute, and/or modify this program
9 * under the terms of the GNU General Public License, version 2 or any
10 * later version published by the Free Software Foundation.
11 *
12 * A copy of the license can be found at
13 * http://www.robotcub.org/icub/license/gpl.txt
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details
19 */
27 //#pragma once
28 #ifndef ICUB_SIMH
29 #define ICUB_SIMH
30 
31 #include <yarp/os/Os.h>
32 #include <yarp/os/Semaphore.h>
33 
34 #include "SDL_thread.h"
35 #include "SDL.h"
36 #include "SDL_timer.h"
37 #include "SDL_opengl.h"
38 #include "rendering.h"
39 #include <ode/ode.h>
40 #include <assert.h>
41 #include "iCub.h"
42 #include <stdio.h>
43 #include "world.h"
44 #include <cstdlib>
45 #include <iostream>
46 #include <fstream>
47 #include <string>
48 #include <yarp/os/Time.h>
49 #include "pidfilter.h"
50 #include <time.h>
51 #include <signal.h>
52 
53 #include "VideoTexture.h"
54 #include "RobotStreamer.h"
55 #include "RobotConfig.h"
56 #include "Simulation.h"
57 
60 
61 #define FAKE_TAXEL_ID 10000
62 
63 extern Semaphore ODE_access;
64 
70 class OdeSdlSimulation : public Simulation {
71 public:
78 
79  void init(RobotStreamer *streamer, RobotConfig *config);
80 
87 
93  void drawView(bool left, bool right, bool wide);
94 
100  void clearBuffer();
101 
110  void simLoop(int h,int w);
111 
112  bool checkSync(bool reset = false);
113 
114  virtual bool getImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& target);
115 
116  virtual bool getTrqData(Bottle data);
117 
118 private:
119  static void draw();
120 
121  static void printStats();
122 
123  static void handle_key_down(SDL_keysym* keysym);
124 
125  static void handle_mouse_motion(SDL_MouseMotionEvent* mousemotion);
126 
127  static void process_events(void);
128 
129  static void nearCallback (void *data, dGeomID o1, dGeomID o2);
130 
131  // returns true if the body with the bodyID is a touch-sensitive body, returns false otherwise.
132  static bool isBodyTouchSensitive (dBodyID bodyID);
133 
134  static void inspectHandTouch_continuousValued(Bottle& report);
135 
136  static void inspectHandTouch_icubSensors(Bottle& reportLeft, Bottle& reportRight, bool boolean);
137 
138  static void getAngles(const dReal *m, float& z, float& y, float& x);
139 
140  static void initViewpoint();
141 
142  static void mouseMovement(float x, float y);
143 
144  static void draw_screen();
145 
146  static void retreiveInertialData(Bottle& inertialReport);
147 
148  static Uint32 ODE_process(Uint32 interval, void *param);
149 
150  //static int thread_func(void *unused);
151  static int thread_ode(void *unused);
152 
153  static void sighandler(int sig);
154 
155  static void initContactICubSkinEmulMap(void);
156  static void resetContactICubSkinEmulMap(void);
157  static void printContactICubSkinEmulMap(void); //for debugging
158 
159  // in the self_collisions regime, this is to ignore collisions between certain geoms, such as upper arm covers colliding with torso
160  static bool selfCollisionOnIgnoreList(string geom1_string, string geom2_string);
161 
162  static void inspectWholeBodyContactsAndSendTouch(); //We emulate the skin of the iCub - covers + fingertips; the rest of the geoms will only be processed by the skinEvents
163  static void mapPositionIntoTaxelList(const SkinPart skin_part,const Vector geo_center_link_FoR,std::vector<unsigned int>& list_of_taxels);
164  static void pushTriangleToTaxelList(const int startingTaxelID,std::vector<unsigned int>& list_of_taxels);
165  static void mapFingertipIntoTaxelList(const HandPart hand_part,std::vector<unsigned int>& list_of_taxels);
166  static std::string getGeomClassName(const int geom_class, std::string & s);
167 
171 
172 };
173 
174 #endif
175 
virtual bool getTrqData(Bottle data)
Definition: iCub_Sim.cpp:1621
OdeSdlSimulation()
Constructor.
Definition: iCub_Sim.cpp:1395
The iCub header file.
Header file for the video stream texture.
void drawView(bool left, bool right, bool wide)
Render the requested view.
Definition: iCub_Sim.cpp:1323
Header for the world creation.
virtual bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &target)
Definition: iCub_Sim.cpp:1632
Semaphore ODE_access
Header to implement the PID filter.
void clearBuffer()
Signal that we&#39;re done with a view.
Definition: iCub_Sim.cpp:1391
Header file for the rendering.
void simLoop(int h, int w)
Run the simulation.
Definition: iCub_Sim.cpp:1224
~OdeSdlSimulation()
Destructor.
Definition: iCub_Sim.cpp:1607
bool checkSync(bool reset=false)
Definition: iCub_Sim.cpp:1612
Main simulation driver, using SDL and ODE.
Definition: iCub_Sim.h:70
void init(RobotStreamer *streamer, RobotConfig *config)
Initialization.
Definition: iCub_Sim.cpp:1398