grav_comp.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #include "Eigen/Dense"
6 
7 namespace hebi {
8 namespace util {
9 
14 static Eigen::VectorXd getGravCompEfforts(
15  const hebi::robot_model::RobotModel& model,
16  const Eigen::VectorXd& masses,
17  const hebi::GroupFeedback& feedback)
18 {
19  // Update gravity from base module:
20  auto base_accel = feedback[0].imu().accelerometer().get();
21  Vector3d gravity(-base_accel.getX(),
22  -base_accel.getY(),
23  -base_accel.getZ());
24 
25  // Normalize gravity vector (to 1g, or 9.8 m/s^2)
26  Eigen::Vector3d normed_gravity = gravity;
27  normed_gravity /= normed_gravity.norm();
28  normed_gravity *= 9.81;
29 
30  size_t num_dof = model.getDoFCount();
31  size_t num_frames = model.getFrameCount(robot_model::FrameType::CenterOfMass);
32 
34  model.getJ(robot_model::FrameType::CenterOfMass, feedback.getPosition(), jacobians);
35 
36  // Get torque for each module
37  // comp_torque = J' * wrench_vector
38  // (for each frame, sum this quantity)
39  Eigen::VectorXd comp_torque(num_dof);
40  comp_torque.setZero();
41 
42  // Wrench vector
43  Eigen::VectorXd wrench_vec(6); // For a single frame; this is (Fx/y/z, tau x/y/z)
44  wrench_vec.setZero();
45  for (size_t i = 0; i < num_frames; ++i)
46  {
47  // Set translational part
48  for (size_t j = 0; j < 3; ++j)
49  {
50  wrench_vec[j] = -normed_gravity[j] * masses[i];
51  }
52 
53  // Add the torques for each joint to support the mass at this frame
54  comp_torque += jacobians[i].transpose() * wrench_vec;
55  }
56 
57  return comp_torque;
58 }
59 
60 } // namespace util
61 } // namespace hebi
62 
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
static Eigen::VectorXd getGravCompEfforts(const hebi::robot_model::RobotModel &model, const Eigen::VectorXd &masses, const hebi::GroupFeedback &feedback)
Definition: grav_comp.hpp:14
Definition: arm.cpp:5
size_t getFrameCount(FrameType frame_type) const
Return the number of frames in the forward kinematics.
Represents a chain or tree of robot elements (rigid bodies and joints).
std::vector< MatrixXd, Eigen::aligned_allocator< Eigen::MatrixXd >> MatrixXdVector
Definition: robot_model.hpp:17
void getJ(FrameType, const Eigen::VectorXd &positions, MatrixXdVector &jacobians) const
Generates the Jacobian for each frame in the given kinematic tree.
size_t getDoFCount() const
Returns the number of settable degrees of freedom in the kinematic tree. (This is equal to the number...
Eigen::VectorXd getPosition() const
Convenience function for returning feedback position values.


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Thu May 28 2020 03:14:44