A sparse MPC solver for walking motion generation.
oru_walk_init.cpp
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 #include "oru_walk.h"
9 
10 
11 /**
12  * @brief Initializes variables, that are necessary for fast reading of data from memory.
13  */
14 void oru_walk::initFastRead(const vector<string>& joint_names)
15 {
16  // Sensors names
17  vector<string> fSensorKeys;
18 
19  fSensorKeys.clear();
20  fSensorKeys.resize(JOINTS_NUM);
21 
22 
23  // connect to sensors
24  for (int i = 0; i < JOINTS_NUM; i++)
25  {
26  fSensorKeys[i] = joint_names[i] + "/Position/Sensor/Value";
27  }
28  // Create the fast memory access
29  access_sensor_values->ConnectToVariables(getParentBroker(), fSensorKeys, false);
30 
31 
32  last_dcm_time_ms_ptr = (int *) memory_proxy->getDataPtr("DCM/Time");
33 }
34 
35 
36 
37 /**
38  * @brief Initializes variables, that are necessary for fast sending of parameters to DCM.
39  */
40 void oru_walk::initFastWrite(const vector<string>& joint_names)
41 {
42  ALValue jointAliases;
43 
44  jointAliases.arraySetSize(2);
45  jointAliases[1].arraySetSize(JOINTS_NUM);
46 
47 
48  // positions of actuators.
49  jointAliases[0] = std::string("jointActuator"); // Alias for all joint actuators
50  // Create alias
51  try
52  {
53  for (int i = 0; i < JOINTS_NUM; i++)
54  {
55  jointAliases[1][i] = joint_names[i] + "/Position/Actuator/Value";
56  }
57  dcm_proxy->createAlias(jointAliases);
58  }
59  catch (const ALError &e)
60  {
61  ORUW_THROW_ERROR("Error when creating Alias: ", e);
62  }
63 
64 
65  // stiffness of actuators.
66  jointAliases[0] = std::string("jointStiffness"); // Alias for all actuators
67  // Create alias
68  try
69  {
70  for (int i = 0; i < JOINTS_NUM; i++)
71  {
72  jointAliases[1][i] = joint_names[i] + "/Hardness/Actuator/Value";
73  }
74  dcm_proxy->createAlias(jointAliases);
75  }
76  catch (const ALError &e)
77  {
78  ORUW_THROW_ERROR("Error when creating Alias: ", e);
79  }
80 
81 
82 
83  // access to the actuators in the lower body only
84  jointAliases[1].clear();
85  jointAliases[1].arraySetSize(LOWER_JOINTS_NUM);
86 
87  // positions of actuators.
88  jointAliases[0] = std::string("lowerJointActuator"); // Alias for all joint actuators
89  // Create alias
90  try
91  {
92  for (int i = 0; i < LOWER_JOINTS_NUM; i++)
93  {
94  jointAliases[1][i] = joint_names[i] + "/Position/Actuator/Value";
95  }
96  dcm_proxy->createAlias(jointAliases);
97  }
98  catch (const ALError &e)
99  {
100  ORUW_THROW_ERROR("Error when creating Alias: ", e);
101  }
102 }
103 
104 
105 
106 /**
107  * @brief Initialize commands, that will be sent to DCM.
108  */
110 {
111  // create the structure of the commands
112  joint_commands.arraySetSize(6);
113  joint_commands[0] = string("lowerJointActuator");
114  joint_commands[1] = string("ClearAll");
115  joint_commands[2] = string("time-separate");
116  joint_commands[3] = 0;
117 
118  joint_commands[4].arraySetSize(1);
119 
120  joint_commands[5].arraySetSize(LOWER_JOINTS_NUM); // For all joints
121  for (int i=0; i < LOWER_JOINTS_NUM; i++)
122  {
123  joint_commands[5][i].arraySetSize(1);
124  }
125 }
126 
127 
128 void oru_walk::initJointAngles(ALValue &init_joint_angles)
129 {
130  init_joint_angles[L_HIP_YAW_PITCH][0] = 0.0;
131  // note, that R_HIP_YAW_PITCH is controlled by the same motor as L_HIP_YAW_PITCH
132  init_joint_angles[R_HIP_YAW_PITCH][0] = 0.0;
133 
134  init_joint_angles[L_HIP_ROLL][0] = -0.000384;
135  init_joint_angles[L_HIP_PITCH][0] = -0.598291;
136  init_joint_angles[L_KNEE_PITCH][0] = 1.009413;
137  init_joint_angles[L_ANKLE_PITCH][0] = -0.492352;
138  init_joint_angles[L_ANKLE_ROLL][0] = 0.000469;
139 
140  init_joint_angles[R_HIP_ROLL][0] = -0.000384;
141  init_joint_angles[R_HIP_PITCH][0] = -0.598219;
142  init_joint_angles[R_KNEE_PITCH][0] = 1.009237;
143  init_joint_angles[R_ANKLE_PITCH][0] = -0.492248;
144  init_joint_angles[R_ANKLE_ROLL][0] = 0.000469;
145 
146  init_joint_angles[L_SHOULDER_PITCH][0] = 1.418908;
147  init_joint_angles[L_SHOULDER_ROLL][0] = 0.332836;
148  init_joint_angles[L_ELBOW_YAW][0] = -1.379108;
149  init_joint_angles[L_ELBOW_ROLL][0] = -1.021602;
150  init_joint_angles[L_WRIST_YAW][0] = -0.013848;
151 
152  init_joint_angles[R_SHOULDER_PITCH][0] = 1.425128;
153  init_joint_angles[R_SHOULDER_ROLL][0] = -0.331386;
154  init_joint_angles[R_ELBOW_YAW][0] = 1.383626;
155  init_joint_angles[R_ELBOW_ROLL][0] = 1.029356;
156  init_joint_angles[R_WRIST_YAW][0] = -0.01078;
157 
158  init_joint_angles[HEAD_PITCH][0] = 0.0;
159  init_joint_angles[HEAD_YAW][0] = 0.0;
160 }
void initJointAngles(ALValue &)
void initFastWrite(const vector< string > &)
Initializes variables, that are necessary for fast sending of parameters to DCM.
#define ORUW_THROW_ERROR(message, error)
Definition: oru_walk.h:66
ALPtr< DCMProxy > dcm_proxy
Definition: oru_walk.h:143
void initWalkCommands()
Initialize commands, that will be sent to DCM.
int * last_dcm_time_ms_ptr
Definition: oru_walk.h:128
ALPtr< ALMemoryProxy > memory_proxy
Definition: oru_walk.h:144
ALValue joint_commands
Definition: oru_walk.h:131
ALPtr< ALMemoryFastAccess > access_sensor_values
Definition: oru_walk.h:127
void initFastRead(const vector< string > &)
Initializes variables, that are necessary for fast reading of data from memory.