40 double M =
mass_.sum();
44 for (
int i = 0; i <
kinematics[0].Phi.rows(); ++i)
56 for (
int i = 0; i <
dim_; ++i) phi(i) = com[i];
73 if (jacobian.rows() !=
dim_ || jacobian.cols() != x.rows())
ThrowNamed(
"Wrong size of jacobian! " << x.rows());
79 double M =
mass_.sum();
81 for (
int i = 0; i <
kinematics[0].Phi.rows(); ++i)
98 for (std::weak_ptr<KinematicElement> welement :
scene_->GetKinematicTree().GetTree())
100 std::shared_ptr<KinematicElement> element = welement.lock();
101 if (element->is_robot_link || element->closest_robot_link.lock())
103 double mass = element->segment.getInertia().getMass();
108 Eigen::MatrixXd jacobian_com_local =
scene_->GetKinematicTree().Jacobian(element, cog,
nullptr,
KDL::Frame());
109 com += com_local.p * mass;
110 jacobian += jacobian_com_local.topRows(
dim_) * mass;
114 geometry_msgs::Point pt;
115 pt.
x = com_local.p[0];
116 pt.y = com_local.p[1];
117 pt.z = com_local.p[2];
123 if (M == 0.0)
return;
125 jacobian = jacobian / M;
127 for (
int i = 0; i <
dim_; ++i) phi(i) = com[i];
157 HIGHLIGHT_NAMED(
"CenterOfMass",
"!!! WARNING !!! This may be broken and cause a segfault if you update the scene after initialisation as the weak_ptr in GetTreeMap() expire!");
162 for (std::size_t i = 0; i <
frames_.size(); ++i)
164 if (
frames_[i].frame_B_link_name !=
"")
166 ThrowNamed(
"Requesting CenterOfMass frame with base other than root! '" <<
frames_[i].frame_A_link_name <<
"'");
168 frames_[i].frame_A_link_name =
scene_->GetKinematicTree().GetTreeMap().at(
frames_[i].frame_A_link_name).lock()->segment.getName();
169 frames_[i].frame_A_offset.p =
scene_->GetKinematicTree().GetTreeMap().at(
frames_[i].frame_A_link_name).lock()->segment.getInertia().getCOG();
170 mass_(i) =
scene_->GetKinematicTree().GetTreeMap().at(
frames_[i].frame_A_link_name).lock()->segment.getInertia().getMass();
195 com_marker_.type = visualization_msgs::Marker::CYLINDER;
202 com_marker_.action = visualization_msgs::Marker::ADD;
205 "exotica/" +
scene_->GetRootFrameName();
208 com_pub_ = Server::Advertise<visualization_msgs::Marker>(object_name_ +
"/com_marker", 1,
true);
void publish(const boost::shared_ptr< M > &message) const
std::vector< KinematicFrameRequest > frames_
Eigen::Ref< Eigen::VectorXd > VectorXdRef
ros::Publisher com_links_pub_
void Update(Eigen::VectorXdRefConst x, Eigen::VectorXdRef phi) override
std::shared_ptr< Scene > ScenePtr
void AssignScene(ScenePtr scene) override
visualization_msgs::Marker com_marker_
visualization_msgs::Marker com_links_marker_
REGISTER_TASKMAP_TYPE("CenterOfMass", exotica::CenterOfMass)
CenterOfMassInitializer parameters_
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
int TaskSpaceDim() override
#define HIGHLIGHT_NAMED(name, x)
Eigen::Ref< Eigen::MatrixXd > MatrixXdRef