SCL  1.0
Standard Control Library : Control, dynamics, physics, and simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Groups Pages
CTaskBase.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 CTaskBase.hpp
24  * Encapsulates a task servo and a task model
25  *
26  * Created on: May 5, 2010
27  *
28  * Copyright (C) 2010
29  *
30  * Author: Samir Menon <smenon@stanford.edu>
31  */
32 
33 #ifndef CTASKBASE_HPP_
34 #define CTASKBASE_HPP_
35 
36 #include <scl/DataTypes.hpp>
37 
38 #include <scl/control/task/data_structs/STaskBase.hpp>
39 #include <scl/data_structs/SRobotIO.hpp>
40 
41 #include <scl/dynamics/CDynamicsBase.hpp>
42 
43 #ifdef DEBUG
44 #include <cassert>
45 #endif
46 
47 namespace scl {
48 
54 class CTaskBase {
55 public:
56  /* **************************************************************
57  * Computation Functions
58  * ************************************************************** */
60  virtual bool computeServo(const SRobotSensors* arg_sensors)=0;
61 
63  virtual bool computeModel(const SRobotSensors* arg_sensors)=0;
64 
65  /* **************************************************************
66  * Status Get/Set Functions
67  * ************************************************************** */
72  virtual STaskBase* getTaskData()=0;
73 
75  virtual bool setGoalPos(const Eigen::VectorXd & arg_goal) { return false; }
76 
78  virtual bool setGoalVel(const Eigen::VectorXd & arg_goal) { return false; }
79 
81  virtual bool setGoalAcc(const Eigen::VectorXd & arg_goal) { return false; }
82 
84  virtual bool getGoalPos(Eigen::VectorXd & arg_goal) const { return false; }
85 
87  virtual bool getGoalVel(Eigen::VectorXd & arg_goal) const { return false; }
88 
90  virtual bool getGoalAcc(Eigen::VectorXd & arg_goal) const { return false; }
91 
93  virtual bool getPos(Eigen::VectorXd & arg_pos) const { return false; }
94 
96  virtual bool getVel(Eigen::VectorXd & arg_vel) const { return false; }
97 
99  virtual bool getAcc(Eigen::VectorXd & arg_acc) const { return false; }
100 
101  /* **************************************************************
102  * Initialization Functions
103  * ************************************************************** */
106  has_been_init_(false),
107  dynamics_(S_NULL) {}
108 
110  virtual ~CTaskBase(){}
111 
116  virtual bool init(STaskBase* arg_task_data,
117  CDynamicsBase* arg_dynamics)=0;
118 
120  virtual void reset()=0;
121 
124  virtual sBool hasBeenInit() { return has_been_init_; }
125 
126  /* **************************************************************
127  * Runtime Enable/Disable Functions
128  * ************************************************************** */
135  virtual sBool setActivated(sBool arg_activate)
136  {
137  STaskBase* t_ds = getTaskData();
138  if(S_NULL == t_ds) { return false; } //Can't access task data struct.
139  if(!t_ds->has_been_init_) { return false; } //Task data struct not initialized
140  t_ds->has_been_activated_=arg_activate;
141  return true;
142  }
143 
147  {
148  STaskBase* t_ds = getTaskData();
149  if(S_NULL == t_ds) { return false; } //Can't access task data.
150 #ifdef DEBUG
151  if(!t_ds->has_been_init_)//If it is not initailized, it shouldn't be activated.
152  { assert(!t_ds->has_been_activated_); }
153 #endif
154  return t_ds->has_been_activated_;
155  }
156 
157 protected:
163 
166 };
167 
168 }
169 
170 #endif /* CTASKBASE_HPP_ */
Definition: STaskBase.hpp:69
virtual void reset()=0
virtual sBool hasBeenInit()
Definition: CTaskBase.hpp:124
CTaskBase()
Definition: CTaskBase.hpp:105
virtual ~CTaskBase()
Definition: CTaskBase.hpp:110
virtual bool getVel(Eigen::VectorXd &arg_vel) const
Definition: CTaskBase.hpp:96
virtual sBool hasBeenActivated()
Definition: CTaskBase.hpp:146
virtual bool getPos(Eigen::VectorXd &arg_pos) const
Definition: CTaskBase.hpp:93
virtual bool getAcc(Eigen::VectorXd &arg_acc) const
Definition: CTaskBase.hpp:99
virtual bool init(STaskBase *arg_task_data, CDynamicsBase *arg_dynamics)=0
virtual bool setGoalPos(const Eigen::VectorXd &arg_goal)
Definition: CTaskBase.hpp:75
virtual bool setGoalAcc(const Eigen::VectorXd &arg_goal)
Definition: CTaskBase.hpp:81
virtual sBool setActivated(sBool arg_activate)
Definition: CTaskBase.hpp:135
virtual bool setGoalVel(const Eigen::VectorXd &arg_goal)
Definition: CTaskBase.hpp:78
Definition: CDynamicsBase.hpp:55
virtual bool getGoalPos(Eigen::VectorXd &arg_goal) const
Definition: CTaskBase.hpp:84
CDynamicsBase * dynamics_
Definition: CTaskBase.hpp:165
bool sBool
Definition: DataTypes.hpp:54
virtual bool getGoalAcc(Eigen::VectorXd &arg_goal) const
Definition: CTaskBase.hpp:90
sBool has_been_init_
Definition: SObject.hpp:72
virtual bool computeModel(const SRobotSensors *arg_sensors)=0
sBool has_been_init_
Definition: CTaskBase.hpp:162
virtual bool getGoalVel(Eigen::VectorXd &arg_goal) const
Definition: CTaskBase.hpp:87
virtual bool computeServo(const SRobotSensors *arg_sensors)=0
virtual STaskBase * getTaskData()=0
Definition: SRobotIO.hpp:49
scl::sBool has_been_activated_
Definition: STaskBase.hpp:81
Definition: CTaskBase.hpp:54