SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
CRobotApp.hpp
1 /* This file is part of scl, a control and simulation library
2 for robots and biomechanical models.
3 
4 scl is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8 
9 Alternatively, you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of
12 the License, or (at your option) any later version.
13 
14 scl is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License and a copy of the GNU General Public License along with
21 scl. If not, see <http://www.gnu.org/licenses/>.
22  */
23 /* \file CRobotApp.hpp
24  *
25  * Created on: Sep 16, 2011
26  *
27  * Copyright (C) 2011
28  *
29  * Author: Samir Menon <smenon@stanford.edu>
30  */
31 
32 #ifndef CROBOTAPP_HPP_
33 #define CROBOTAPP_HPP_
34 
35 //Standard includes
36 #include <scl/DataTypes.hpp>
37 #include <scl/control/task/CTaskBase.hpp>
38 #include <scl/robot/CRobot.hpp>
39 #include <scl/dynamics/tao/CDynamicsTao.hpp>
40 #include <scl/dynamics/scl/CDynamicsScl.hpp>
41 
42 #ifdef GRAPHICS_ON
43 #include <scl/graphics/chai/CGraphicsChai.hpp>
44 #endif
45 
46 namespace scl
47 {
64  class CRobotApp
65  {
66  public:
67  /***********************************************************************
68  * NOTE : You must subclass and implement these to suit your application
69  * Keep in mind that the CRobotApp does most things for you already.
70  ************************************************************************/
72  virtual void stepMySimulation()=0;
73 
78  virtual scl::sBool initMyController(const std::vector<std::string>& argv,
83  sUInt args_already_parsed)=0;
84 
87  { return true; }
88 
92 
93  public:
94  /************************************************************************/
95  /***************NOTE : You should NOT need to modify these **************/
96  /**************** But feel free to use the objects **************/
97  /************************************************************************/
98 
100  CRobotApp();
101 
103  virtual ~CRobotApp(){}
104 
106  scl::sBool init(const std::vector<std::string>& argv);
107 
108 #ifdef GRAPHICS_ON
109  scl::sBool initGraphics(
112  const timespec& arg_ts,
114  const int arg_gr_frm_ctr);
115 #endif
116 
118  virtual void terminate();
119 
123  void runMainLoopThreaded(const int& thread_id);
124 
128  void runMainLoop();
129 
149  void runConsoleShell();
150 
151  //Data types. Feel free to use them.
152  scl::SDatabase* db_; //Generic database (for sharing data)
153 
154  std::vector<std::string> robots_parsed_; //Parsed robots
155 
156  std::string robot_name_; //Currently selected robot
157  std::string ctrl_name_; //Currently selected controller
158 
159  scl::CRobot robot_; //Generic robot
160  scl::SRobotParsed *rob_ds_; //Generic robot data structure
161  scl::SRobotIO* rob_io_ds_; //Access the robot's sensors and actuators
162 
163  scl::CDynamicsTao* dyn_tao_; //Generic tao dynamics
164  scl::CDynamicsScl* dyn_scl_; //Generic tao dynamics
165 
166  scl::sLongLong ctrl_ctr_; //Controller computation counter
167  scl::sFloat t_start_, t_end_; //Start and end times
168 
173  {
174  public:
175  std::string name_;
176  scl::CTaskBase* task_;
177  scl::sInt ui_pt_;
178  scl::sBool has_been_init_;
179 #ifdef GRAPHICS_ON
180  Eigen::VectorXd pos_, pos_des_;
181  chai3d::cGenericObject *chai_pos_,*chai_pos_des_;
182 #endif
183  SUiCtrlPointData() :
184  name_(""),task_(NULL),ui_pt_(-1),
185  has_been_init_(false)
186 #ifdef GRAPHICS_ON
187  , chai_pos_(NULL), chai_pos_des_(NULL)
188 #endif
189  {}
190  };
193  std::vector<SUiCtrlPointData> taskvec_ui_ctrl_point_;
194 
195  //Graphics stuff
196 #ifdef GRAPHICS_ON
197  std::vector<std::string> graphics_parsed_; //Parsed graphics views
198  scl::CGraphicsChai chai_gr_; //Generic chai graphics
199  scl::sLongLong gr_ctr_; //Graphic update counter
200  timespec ts_; //Sleep for graphics (nanoseconds)
201  int gr_frm_skip_; //Graphics frames to skip (single-threaded mode)
202  int gr_frm_ctr_; //Graphics frame counter (single-threaded mode)
203 #endif
204  };
205 }
206 
207 #endif /* CROBOTAPP_HPP_ */
scl::sBool init(const std::vector< std::string > &argv)
Definition: CRobotApp.cpp:88
Definition: CGraphicsChai.hpp:48
std::vector< SUiCtrlPointData > taskvec_ui_ctrl_point_
Definition: CRobotApp.hpp:193
CRobotApp()
Definition: CRobotApp.cpp:71
Definition: SRobotIO.hpp:107
virtual void terminate()
Definition: CRobotApp.cpp:329
virtual scl::sBool initMyController(const std::vector< std::string > &argv, sUInt args_already_parsed)=0
Definition: SRobotParsed.hpp:51
virtual void stepMySimulation()=0
Definition: SDatabase.hpp:239
virtual ~CRobotApp()
Definition: CRobotApp.hpp:103
void runMainLoopThreaded(const int &thread_id)
Definition: CRobotApp.cpp:346
Definition: CRobotApp.hpp:64
Definition: CDynamicsTao.hpp:62
virtual scl::sBool setInitialStateForUIAndDynamics()=0
bool sBool
Definition: DataTypes.hpp:54
Definition: CDynamicsScl.hpp:57
Definition: CRobot.hpp:63
long long sLongLong
Definition: DataTypes.hpp:66
Definition: CRobotApp.hpp:172
double sFloat
Definition: DataTypes.hpp:72
int sInt
Definition: DataTypes.hpp:64
void runMainLoop()
Definition: CRobotApp.cpp:378
void runConsoleShell()
Definition: CRobotApp.cpp:402
virtual scl::sBool registerCustomDynamicTypes()
Definition: CRobotApp.hpp:86
Definition: CTaskBase.hpp:54