A sparse MPC solver for walking motion generation.
oru_walk.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @author Antonio Paolillo
4  * @author Dimitar Dimitrov
5  * @author Alexander Sherikov
6  */
7 
8 
9 #ifndef ORU_WALK_H
10 #define ORU_WALK_H
11 
12 
13 //----------------------------------------
14 // INCLUDES
15 //----------------------------------------
16 
17 // standard headers
18 #include <string> // string
19 
20 
21 // NAO headers
22 #include <qi/log.hpp>
23 
24 #include <alcore/alptr.h>
25 #include <alcore/alerror.h>
26 
27 #include <alcommon/alproxy.h>
28 #include <alcommon/albroker.h>
29 #include <alcommon/almodule.h>
30 
31 #include <alvalue/alvalue.h> // ALValue
32 
33 #include <alproxies/dcmproxy.h>
34 #include <alproxies/almemoryproxy.h>
35 
36 #include <almemoryfastaccess/almemoryfastaccess.h>
37 
38 #include <althread/almutex.h>
39 
40 
41 // other libraries
42 #include <boost/bind.hpp> // callback hook
43 #include <boost/thread.hpp>
44 
45 #include <althread/alcriticalsection.h>
46 
47 
48 // our headers
49 #include "WMG.h" // footsteps & parameters
50 #include "smpc_solver.h" // solver
51 #include "joints_sensors_id.h"
52 #include "nao_igm.h"
53 #include "walk_parameters.h"
54 
55 
56 
57 //----------------------------------------
58 // DEFINITIONS
59 //----------------------------------------
60 
61 
62 using namespace AL;
63 using namespace std;
64 
65 #define ORUW_THROW(message) throw ALERROR(getName(), __FUNCTION__, message)
66 #define ORUW_THROW_ERROR(message,error) throw ALERROR(getName(), __FUNCTION__, message + string (error.what()))
67 
68 
69 
70 /**
71  * @brief The main walking module class.
72  */
73 class oru_walk : public ALModule
74 {
75 public:
76  // constructors / destructors
77  oru_walk(ALPtr<ALBroker> broker, const string& name);
78  ~oru_walk ();
79 
80 
81  // is called automatically when a library is loaded
82  void init();
83 
84 
85 // These methods will be advertised to other modules.
86  void stopWalkingRemote();
87  void initPosition();
88  void setStiffness(const float &);
89  void walk();
90 
91 // EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
92 
93 private:
94  // initialization
95  void initFastRead (const vector<string>&);
96  void initFastWrite (const vector<string>&);
97  void initWalkCommands ();
98  void initJointAngles (ALValue &);
99 
100  void initWalkPattern(WMG &);
101  void initWalkPattern_Straight(WMG &);
102  void initWalkPattern_Diagonal(WMG &);
103  void initWalkPattern_Circular(WMG &);
104  void initSolver();
105 
106 
107  // walking
108  void readSensors (jointState&);
109  bool solveMPCProblem (WMG&, smpc_parameters&);
110  void solveIKsendCommands (const smpc_parameters&, const smpc::state_com &, const int, WMG&);
111 
112  void correctNextSupportPosition(WMG &);
113  void feedbackError (smpc::state_com &);
114 
115  void halt(const char*, const char *);
116  void stopWalking(const char*);
117 
118  void walkControl();
119  // periodically called callback function
120  void dcmCallback();
121 
122 
123 // private variables
124  ProcessSignalConnection dcm_callback_connection;
125 
126  // Used for fast memory access
127  ALPtr<ALMemoryFastAccess> access_sensor_values;
129 
130  // Used to store command to send
131  ALValue joint_commands;
132 
133 
134  nao_igm nao;
135  double ref_joint_angles[LOWER_JOINTS_NUM];
136 
138  smpc::solver *solver;
139 
142 
143  ALPtr<DCMProxy> dcm_proxy;
144  ALPtr<ALMemoryProxy> memory_proxy;
145 
146  boost::condition_variable walk_control_condition;
147  boost::mutex walk_control_mutex;
148 };
149 
150 #endif // ORU_WALK_H
int dcm_loop_counter
Definition: oru_walk.h:140
int last_dcm_time_ms
Definition: oru_walk.h:141
nao_igm nao
Definition: oru_walk.h:134
smpc::solver * solver
Definition: oru_walk.h:138
ALPtr< DCMProxy > dcm_proxy
Definition: oru_walk.h:143
walkParameters wp
Definition: oru_walk.h:137
int * last_dcm_time_ms_ptr
Definition: oru_walk.h:128
ALPtr< ALMemoryProxy > memory_proxy
Definition: oru_walk.h:144
boost::condition_variable walk_control_condition
Definition: oru_walk.h:146
A container for parameters.
ALValue joint_commands
Definition: oru_walk.h:131
ProcessSignalConnection dcm_callback_connection
Definition: oru_walk.h:124
ALPtr< ALMemoryFastAccess > access_sensor_values
Definition: oru_walk.h:127
boost::mutex walk_control_mutex
Definition: oru_walk.h:147
The main walking module class.
Definition: oru_walk.h:73