qiayuanl / legged_control

Nonlinear MPC and WBC framework for legged robot based on OCS2 and ros-controls
BSD 3-Clause "New" or "Revised" License
854 stars 217 forks source link

imu subscriber stopping subscribing ?!! #41

Closed elpimous closed 1 year ago

elpimous commented 1 year ago

Hi, my imu subscriber is into UnitreeHW.pp -> init() ros::Subscriber sub = root_nh.subscribe("imu/data", 1000, &UnitreeHW::imuCallback, this);

The imu callback is :

void UnitreeHW::imuCallback(const sensor_msgs::Imu::ConstPtr& imu_message){

  //ROS_INFO("****************** Imu Orientation x: [%f], y: [%f], z: [%f], w: [%f]", imu_message->orientation.x,
          //imu_message->orientation.y,imu_message->orientation.z,imu_message->orientation.w);
  imuData_.ori_[0]        = imu_message->orientation.x;
  imuData_.ori_[1]        = imu_message->orientation.y;
  imuData_.ori_[2]        = imu_message->orientation.z;
  imuData_.ori_[3]        = imu_message->orientation.w; // TODO : is this 4rd index w, or x ?

  imuData_.angularVel_[0] = imu_message->angular_velocity.x;
  imuData_.angularVel_[1] = imu_message->angular_velocity.y;
  imuData_.angularVel_[2] = imu_message->angular_velocity.z;
  imuData_.linearAcc_[0]  = imu_message->linear_acceleration.x;
  imuData_.linearAcc_[1]  = imu_message->linear_acceleration.y;
  imuData_.linearAcc_[2]  = imu_message->linear_acceleration.z;
}

But, when leaving init() function, imuData_ isn't actualized and keep last value !!

here is my package : https://github.com/elpimous/Legged_Control/blob/c5cad9608556c21835cd147e952fdd2afb53a0d6/legged_unitree/legged_unitree_hw/src/UnitreeHW.cpp#L57

Don't find the problem !! Any help ?

elpimous commented 1 year ago

Small up friends. could it be a Thread problem ? So, waiting for any help, working on a service, to call imu into read() function !

elpimous commented 1 year ago

Up please, friends.. my imu callback is into the class class legged::UnitreeHW Just after the UnitreeHW::init() run, the callback value isn't actualized !!

Please help, all !!

elpimous commented 1 year ago

Up, please !

elpimous commented 1 year ago

well, found, with GPT4 help ! needed to use a specific subscriber : https://github.com/elpimous/Legged_Control/blob/e0a6560fb057e1ba9ec215c66dacd934c2091aa1/legged_unitree/legged_unitree_hw/src/legged_unitree_hw.cpp#L66