Skip to content

Commit abf12d0

Browse files
committed
we finally achieved neo
1 parent dc7ad52 commit abf12d0

5 files changed

Lines changed: 40 additions & 24 deletions

File tree

94.2 KB
Loading

pkgs/dodge_it/src/smith.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,42 @@ double objectiveFunc(const std::vector<double> &masked_q,
8080
std::vector<double> &grad, void *data) {
8181
(void)grad; // grad is not needed because of COBYLA / BOBYGA
8282
auto objData = reinterpret_cast<ObjFuncData *>(data);
83-
std::vector<double> unmasked_q = objData->rbdl->unmaskVec(masked_q, 0.0);
83+
auto rbdl = objData->rbdl;
84+
std::vector<double> unmasked_q = rbdl->unmaskVec(masked_q, 0.0);
8485
const size_t q_size = unmasked_q.size();
8586

87+
// sync right foot
88+
unmasked_q[rbdl->jointName2qIdx("right_hip_pitch_joint", false)] =
89+
unmasked_q[rbdl->jointName2qIdx("left_hip_pitch_joint", false)];
90+
unmasked_q[rbdl->jointName2qIdx("right_knee_joint", false)] =
91+
unmasked_q[rbdl->jointName2qIdx("left_knee_joint", false)];
92+
unmasked_q[rbdl->jointName2qIdx("right_ankle_pitch_joint", false)] =
93+
unmasked_q[rbdl->jointName2qIdx("left_ankle_pitch_joint", false)];
8694
// ---------- DEBUG for visualization ----------
87-
objData->rbdl->publishJoints(masked_q);
95+
rbdl->publishJoints(unmasked_q);
8896
// ---------------------------------------------
8997

90-
auto model = *objData->rbdl->get_model();
98+
auto model = *rbdl->get_model();
9199
Polygon PoS = objData->PoS;
92100
VectorNd qVec = VectorNd::Zero(q_size);
93101
for (size_t i = 0; i < q_size; i++) {
94102
qVec[i] = unmasked_q[i];
95103
}
96104
VectorNd qDotVec = VectorNd::Zero(q_size);
97-
qDotVec = objData->rbdl->unmaskVec(objData->rbdl->get_qdot(), 0.0);
105+
qDotVec = rbdl->unmaskVec(rbdl->get_qdot(), 0.0);
98106
Vector3d world_CoM = Vector3d::Zero();
99107
Scalar totalMass = 0.0;
100108
RigidBodyDynamics::Utils::CalcCenterOfMass(model, qVec, qDotVec, NULL,
101109
totalMass, world_CoM);
102-
Vector3d gnd_CoM =
103-
objData->rbdl->base2body(world_CoM, GND_APPROX_FRAME, qVec);
110+
Vector3d gnd_CoM = rbdl->base2body(world_CoM, GND_APPROX_FRAME, qVec);
104111
Point CoMpt = Point(gnd_CoM[0], gnd_CoM[1]);
105112
double stability = stabilityCriteria(CoMpt, PoS);
106113

107114
return stability;
108115
}
109116

110117
double limboConstraint(const std::vector<double> &masked_q,
111-
std::vector<double> &grad, void *data) {
118+
std::vector<double> &grad, void *data) {
112119
(void)grad; // grad is not needed because of COBYLA / BOBYGA
113120
auto castedData = reinterpret_cast<LimboConstraintData *>(data);
114121
neo_utils::RBDLWrapper *rbdl = castedData->rbdl;
@@ -125,7 +132,6 @@ double limboConstraint(const std::vector<double> &masked_q,
125132
Vector3d bodyOriginInRef =
126133
rbdl->base2body(bodyOriginInWorld, GND_APPROX_FRAME, vec_q);
127134

128-
129135
const double dz = bodyOriginInRef[2] + zInRef;
130136
std::cout << "\r" << std::setw(10) << iterCounter++ << ": " << dz
131137
<< std::flush;
@@ -134,7 +140,7 @@ double limboConstraint(const std::vector<double> &masked_q,
134140
}
135141

136142
double relBodyConstraint(const std::vector<double> &masked_q,
137-
std::vector<double> &grad, void *data) {
143+
std::vector<double> &grad, void *data) {
138144
(void)grad; // grad is not needed because of COBYLA / BOBYGA
139145
auto castedData = reinterpret_cast<RelBodyConstraintData *>(data);
140146
neo_utils::RBDLWrapper *rbdl = castedData->rbdl;
@@ -187,12 +193,12 @@ int main(int argc, char **argv) {
187193
neo_utils::RBDLWrapper *rbdlWrapper = new neo_utils::RBDLWrapper();
188194
// put robot into default position
189195
std::vector<double> q_0(rbdlWrapper->get_q().size(), 0.0);
190-
q_0[rbdlWrapper->jointName2qIdx("left_hip_pitch_joint")] = 1.0;
191-
q_0[rbdlWrapper->jointName2qIdx("right_hip_pitch_joint")] = 1.0;
196+
//q_0[rbdlWrapper->jointName2qIdx("left_hip_pitch_joint")] = 1.0;
197+
//q_0[rbdlWrapper->jointName2qIdx("right_hip_pitch_joint")] = 1.0;
192198
q_0[rbdlWrapper->jointName2qIdx("left_knee_joint")] = 1.5;
193199
q_0[rbdlWrapper->jointName2qIdx("right_knee_joint")] = 1.5;
194-
q_0[rbdlWrapper->jointName2qIdx("right_ankle_pitch_joint")] = -0.8;
195-
q_0[rbdlWrapper->jointName2qIdx("left_ankle_pitch_joint")] = -0.8;
200+
//q_0[rbdlWrapper->jointName2qIdx("right_ankle_pitch_joint")] = -0.8;
201+
//q_0[rbdlWrapper->jointName2qIdx("left_ankle_pitch_joint")] = -0.8;
196202
rbdlWrapper->publishJoints(q_0);
197203
//
198204

@@ -212,9 +218,8 @@ int main(int argc, char **argv) {
212218
"right_shoulder_yaw_joint", "left_elbow_joint", "right_elbow_joint",
213219
"torso_joint",
214220
// ---------- right leg ----------
215-
//"right_hip_pitch_joint", "right_knee_joint",
216-
//"right_ankle_pitch_joint"
217-
});
221+
"right_hip_pitch_joint", "right_knee_joint",
222+
"right_ankle_pitch_joint"});
218223

219224
const int q_size = rbdlWrapper->get_jointNames().size();
220225
std::vector<double> q_lb(q_size);
@@ -245,9 +250,9 @@ int main(int argc, char **argv) {
245250
globalOpt.set_lower_bounds(q_lb);
246251
globalOpt.set_upper_bounds(q_ub);
247252
globalOpt.set_min_objective(objectiveFunc, &objFuncData);
248-
globalOpt.add_equality_constraint(rightFeetConstraint, rbdlWrapper,
249-
1e-3);
250-
LimboConstraintData headLimboData = { rbdlWrapper, "lidar_link", -0.166 };
253+
// globalOpt.add_equality_constraint(rightFeetConstraint, rbdlWrapper,
254+
// 1e-3);
255+
LimboConstraintData headLimboData = {rbdlWrapper, "lidar_link", -0.166};
251256
globalOpt.add_inequality_constraint(limboConstraint, &headLimboData, 1e-3);
252257

253258
globalOpt.set_ftol_abs(1e-8);

pkgs/neo_utils/include/neo_utils/rbdlWrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RBDLWrapper {
9191
std::unordered_map<int, int> masked2qIdxMap;
9292
};
9393
RBDLWrapper(bool floatingBase = false);
94-
int jointName2qIdx(const std::string &jointName) const;
94+
int jointName2qIdx(const std::string &jointName, bool masked = true) const;
9595
void updateMask(const std::vector<std::string> &maskedOutJoints);
9696

9797
template <typename T>

pkgs/neo_utils/src/rbdlWrapper.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ std::vector<std::string> neo_utils::RBDLWrapper::get_jointNames() const {
5757
return maskVec(jointNames);
5858
}
5959

60-
int neo_utils::RBDLWrapper::jointName2qIdx(const std::string &jointName) const {
60+
int neo_utils::RBDLWrapper::jointName2qIdx(const std::string &jointName, bool masked) const {
6161
auto iter = jointName2qIdxMap.find(jointName);
6262
if (iter == jointName2qIdxMap.end()) return -1;
6363
const int originalIdx = iter->second;
64-
return mask.qIdx2masked(originalIdx);
64+
if (masked)
65+
return mask.qIdx2masked(originalIdx);
66+
else
67+
return originalIdx;
6568
}
6669

6770
/**
@@ -94,7 +97,16 @@ void neo_utils::RBDLWrapper::updateMask(
9497
std::vector<std::string> neo_utils::RBDLWrapper::publishJoints(
9598
std::vector<double> q) {
9699
std::vector<std::string> errorJointNames = {};
97-
std::vector<double> unmasked_q = unmaskVec(q, 0.0);
100+
101+
// decides between masked and unmasked
102+
std::vector<double> unmasked_q;
103+
if (mask.size() == q.size()) {
104+
unmasked_q = unmaskVec(q, 0.0); // still masked
105+
} else if ((size_t)this->q.size() == q.size()) {
106+
unmasked_q = q; // already unmasked
107+
} else {
108+
return jointNames; // some nonsense vector
109+
}
98110

99111
MsgJointState msg;
100112
msg.position = {};

pkgs/point_calculator/src/support_polygon.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ int main(int argc, char **argv) {
210210
auto stabilityPub =
211211
node->create_publisher<std_msgs::msg::Float32>("stability", 10);
212212

213-
auto rbdlWrapper = new neo_utils::RBDLWrapper();
214213
while (rclcpp::ok()) {
215214
rclcpp::spin_some(node);
216215

0 commit comments

Comments
 (0)