sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
talos-control-manager.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2015, Andrea Del Prete, LAAS-CNRS
3  *
4  * This file is part of sot-torque-control.
5  * sot-torque-control is free software: you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation, either version 3 of
8  * the License, or (at your option) any later version.
9  * sot-torque-control is distributed in the hope that it will be
10  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details. You should
13  * have received a copy of the GNU Lesser General Public License along
14  * with sot-torque-control. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __sot_torque_control_control_manager_H__
18 #define __sot_torque_control_control_manager_H__
19 
20 /* --------------------------------------------------------------------- */
21 /* --- API ------------------------------------------------------------- */
22 /* --------------------------------------------------------------------- */
23 
24 #if defined(WIN32)
25 #if defined(__sot_torque_control_control_manager_H__)
26 #define TALOS_CONTROL_MANAGER_EXPORT __declspec(dllexport)
27 #else
28 #define TALOS_CONTROL_MANAGER_EXPORT __declspec(dllimport)
29 #endif
30 #else
31 #define TALOS_CONTROL_MANAGER_EXPORT
32 #endif
33 
34 /* --------------------------------------------------------------------- */
35 /* --- INCLUDE --------------------------------------------------------- */
36 /* --------------------------------------------------------------------- */
37 
38 #include <pinocchio/fwd.hpp>
39 
40 // include pinocchio first
41 
42 #include <dynamic-graph/signal-helper.h>
43 
44 #include <map>
45 #include <sot/core/matrix-geometry.hh>
46 #include <sot/core/robot-utils.hh>
47 
48 #include "boost/assign.hpp"
49 
50 namespace dynamicgraph {
51 namespace sot {
52 namespace dg = dynamicgraph;
53 namespace talos_balance {
54 
55 /* --------------------------------------------------------------------- */
56 /* --- CLASS ----------------------------------------------------------- */
57 /* --------------------------------------------------------------------- */
58 
60 #define CTRL_MODE_TRANSITION_TIME_STEP 1000.0
61 
62 class CtrlMode {
63  public:
64  int id;
65  std::string name;
66 
67  CtrlMode() : id(-1), name("None") {}
68  CtrlMode(int id, const std::string& name) : id(id), name(name) {}
69 };
70 
71 std::ostream& operator<<(std::ostream& os, const CtrlMode& s) {
72  os << s.id << "_" << s.name;
73  return os;
74 }
75 
77  : public ::dynamicgraph::Entity {
80  DYNAMIC_GRAPH_ENTITY_DECL();
81 
82  public:
83  /* --- CONSTRUCTOR ---- */
84  TalosControlManager(const std::string& name);
85 
89  void init(const double& dt, const std::string& robotRef);
90 
91  /* --- SIGNALS --- */
92  std::vector<dynamicgraph::SignalPtr<dynamicgraph::Vector, int>*>
94  std::vector<dynamicgraph::SignalPtr<bool, int>*>
97  std::vector<dynamicgraph::Signal<dynamicgraph::Vector, int>*>
99 
103 
104  /* --- COMMANDS --- */
105 
107  void addCtrlMode(const std::string& name);
108  void ctrlModes();
109  void getCtrlMode(const std::string& jointName);
110  void setCtrlMode(const std::string& jointName, const std::string& ctrlMode);
111  void setCtrlMode(const int jid, const CtrlMode& cm);
112 
113  void resetProfiler();
114 
116  // void setNameToId(const std::string& jointName, const double & jointId);
117  // void setJointLimitsFromId(const double &jointId, const double &lq, const
118  // double &uq);
119 
121  // void setJoints(const dynamicgraph::Vector &);
122 
123  // void setStreamPrintPeriod(const double & s);
124 
125  void setSleepTime(const double& seconds);
126  void addEmergencyStopSIN(const std::string& name);
127 
128  /* --- ENTITY INHERITANCE --- */
129  virtual void display(std::ostream& os) const;
130 
131  protected:
132  RobotUtilShrPtr m_robot_util;
133  size_t m_numDofs;
134  bool
136  double m_dt;
141  int m_iter;
142  double m_sleep_time;
144 
145  std::vector<std::string> m_ctrlModes;
146  std::vector<CtrlMode>
148  std::vector<CtrlMode>
150  std::vector<int>
153 
154  bool convertStringToCtrlMode(const std::string& name, CtrlMode& cm);
155  bool convertJointNameToJointId(const std::string& name, unsigned int& id);
156  // bool isJointInRange(unsigned int id, double q);
157  void updateJointCtrlModesOutputSignal();
158 
159 }; // class TalosControlManager
160 
161 } // namespace talos_balance
162 } // namespace sot
163 } // namespace dynamicgraph
164 
165 #endif // #ifndef __sot_torque_control_control_manager_H__
CtrlMode(int id, const std::string &name)
DECLARE_SIGNAL_OUT(u_safe, dynamicgraph::Vector)
raw motor control
std::vector< dynamicgraph::SignalPtr< dynamicgraph::Vector, int > * > m_ctrlInputsSIN
std::vector< CtrlMode > m_jointCtrlModes_previous
control mode of the joints
DECLARE_SIGNAL_OUT(u, dynamicgraph::Vector)
max motor control
double m_dt
true if the entity has been successfully initialized
void setCtrlMode(const std::string &jointName, const std::string &ctrlMode)
int m_iter
true at the first iteration, false otherwise
std::vector< int > m_jointCtrlModesCountDown
previous control mode of the joints
std::vector< dynamicgraph::SignalPtr< bool, int > * > m_emergencyStopVector
std::vector< CtrlMode > m_jointCtrlModes_current
existing control modes
std::vector< dynamicgraph::Signal< dynamicgraph::Vector, int > * > m_jointsCtrlModesSOUT
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Definition: fwd.hh:36
std::ostream & operator<<(std::ostream &os, const CtrlMode &s)
#define TALOS_CONTROL_MANAGER_EXPORT