Tetrapod Project
state_estimator.cpp
Go to the documentation of this file.
2 
3 StateEstimator::StateEstimator(double gait_period, double controller_frequency)
4 {
5  this->InitializeROS();
6 
7  int gait_iteration = 0;
8 
9  number_of_gait_iterations = gait_period * controller_frequency;
10 
12 
14 
16 }
17 
19 {
20  if(!ros::isInitialized())
21  {
22  int argc = 0;
23  char **argv = NULL;
24  ros::init
25  (
26  argc,
27  argv,
28  _node_name,
29  ros::init_options::NoSigintHandler
30  );
31  }
32 
33  this->_node_handle.reset(new ros::NodeHandle(_node_name));
34 
35  this->_generalized_position_subscriber = this->_node_handle->subscribe
36  (
37  "/my_robot/gen_coord",
38  1,
40  this
41  );
42 
43  this->_generalized_velocity_subscriber = this->_node_handle->subscribe
44  (
45  "/my_robot/gen_vel",
46  1,
48  this
49  );
50 
51  this->_body_twist_state_publisher = this->_node_handle->advertise<geometry_msgs::Twist>("/twist_state", 1);
52 }
53 
54 void StateEstimator::GeneralizedPositionCallback(const std_msgs::Float64MultiArrayConstPtr &msg)
55 {
56  for(int i = 0; i < 3; i++)
57  {
58  _attitude(i) = msg->data[i + 3];
59  }
60 }
61 
62 void StateEstimator::GeneralizedVelocityCallback(const std_msgs::Float64MultiArrayConstPtr &msg)
63 {
64  for(int i = 0; i < 3; i++)
65  {
66  _lin_vel_world(i) = msg->data[i];
67  }
68 
69  for(int i = 0; i < 3; i++)
70  {
71  _ang_vel(i) = msg->data[i + 3];
72  }
73 
74  _lin_vel_body(0) = _lin_vel_world(0) * cos(_attitude(2)) + _lin_vel_world(1) * sin(_attitude(2));
75 
76  _lin_vel_body(1) = - _lin_vel_world(0) * sin(_attitude(2)) + _lin_vel_world(1) * cos(_attitude(2));
77 
79 }
80 
82 {
84 
86 
88 
90 
92 
94 
96  {
97  gait_iteration = 0;
98  }
99  else
100  {
101  gait_iteration++;
102  }
103 }
104 
106 {
107  ROS_INFO("VelX: %f\tVelY: %f\tVelZ: %f", _avg_lin_gait_vel_x, _avg_lin_gait_vel_y, _avg_ang_gait_vel_z);
108 }
109 
111 {
113 
114  msg.linear.x = _avg_lin_gait_vel_x;
115  msg.linear.y = _avg_lin_gait_vel_y;
116  msg.linear.z = _lin_vel_body(2);
117 
118  msg.angular.x = _ang_vel(0);
119  msg.angular.y = _ang_vel(1);
120  msg.angular.z = _avg_ang_gait_vel_z;
121 
122  _body_twist_state_publisher.publish(msg);
123 }
ros::Subscriber _generalized_position_subscriber
Eigen::Matrix< double, 3, 1 > _attitude
std::vector< double > _ang_vel_body_z_history
std::vector< double > _lin_vel_body_y_history
double _avg_ang_gait_vel_z
Eigen::Matrix< double, 3, 1 > _lin_vel_body
double _avg_lin_gait_vel_y
ros::Publisher _body_twist_state_publisher
ros::Subscriber _generalized_velocity_subscriber
StateEstimator(double gait_period, double controller_frequency)
std::string _node_name
int number_of_gait_iterations
Eigen::Matrix< double, 3, 1 > _lin_vel_world
std::vector< double > _lin_vel_body_x_history
void GeneralizedPositionCallback(const std_msgs::Float64MultiArrayConstPtr &msg)
void PublishBodyTwistState()
void GeneralizedVelocityCallback(const std_msgs::Float64MultiArrayConstPtr &msg)
double _avg_lin_gait_vel_x
ros::NodeHandlePtr _node_handle
Eigen::Matrix< double, 3, 1 > _ang_vel
Eigen::Matrix< double, 6, 1 > Twist
Definition: kinematics.h:48