Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rm_chassis_controllers/src/chassis_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ void ChassisBase<T...>::updateOdom(const ros::Time& time, const ros::Duration& p
{
slam_updated_ = false;
const auto& slam = slam_rt_buffer_.readFromRT();
try
{
robot_base2lidar_base_ =
robot_state_handle_.lookupTransform(robot_base_frame_id_, lidar_base_frame_id_, ros::Time(0));
}
catch (const tf2::TransformException& ex)
{
ROS_WARN_THROTTLE(1.0, "Failed to update robot_base2lidar_base: %s", ex.what());
}
T_lidar_odom2lidar_base_.setOrigin(
tf2::Vector3(slam->pose.pose.position.x, slam->pose.pose.position.y, slam->pose.pose.position.z));
T_lidar_odom2lidar_base_.setRotation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DualYawController : public Controller
const double pos_real[3], const double pos_des[3], const double pos_des_temp[3],
const double vel_des[3], const double angle_error[3], const double traject_pos_des[3],
const double traject_angle_error[3]) override;
void pose(const ros::Time& time, const ros::Duration& period) override;

private:
bool initBaseYaw(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& controller_nh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class Controller : public controller_interface::MultiInterfaceController<rm_cont
void externalAimTrack(const ros::Time& time);
void direct(const ros::Time& time);
void traj(const ros::Time& time);
virtual void pose(const ros::Time& time, const ros::Duration& period);
bool externalAimIsFresh(const ros::Time& time) const;
bool setDesIntoLimit(double& angle, const urdf::JointConstSharedPtr& joint_urdf, bool update, double current_angle);
void moveJoint(const ros::Time& time, const ros::Duration& period);
Expand Down Expand Up @@ -261,7 +262,8 @@ class Controller : public controller_interface::MultiInterfaceController<rm_cont
RATE,
TRACK,
DIRECT,
TRAJ
TRAJ,
POSE
};
int state_ = RATE;
bool start_ = false;
Expand Down
14 changes: 14 additions & 0 deletions rm_gimbal_controllers/src/dual_yaw_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ void DualYawController::updateYawJoint(const ros::Time& time, const ros::Duratio
publishBaseYawState(time, base_yaw_pos_real, base_yaw_set_point, vel_des, base_yaw_error);
}

void DualYawController::pose(const ros::Time& time, const ros::Duration& period)
{
Controller::pose(time, period);

if (!base_yaw_ctrl_ || !base_yaw_pid_pos_)
return;

const double joint_pos = base_yaw_ctrl_->joint_.getPosition();
const double error = angles::shortest_angular_distance(joint_pos, cmd_gimbal_.pose_base_yaw);
base_yaw_pid_pos_->computeCommand(error, period);
base_yaw_ctrl_->setCommand(base_yaw_pid_pos_->getCurrentCmd());
base_yaw_ctrl_->update(time, period);
}

bool DualYawController::getTrackArmorSetPoint(const ros::Time& time, double& armor_set_point)
{
if (state_ != TRACK || !base_yaw_joint_ || data_track_.header.stamp.isZero())
Expand Down
30 changes: 30 additions & 0 deletions rm_gimbal_controllers/src/gimbal_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ void Controller::update(const ros::Time& time, const ros::Duration& period)
case TRAJ:
traj(time);
break;
case POSE:
pose(time, period);
return;
}
moveJoint(time, period);
}
Expand Down Expand Up @@ -510,6 +513,33 @@ void Controller::traj(const ros::Time& time)
setDes(time, traj[2], traj[1], traj[2]);
}

void Controller::pose(const ros::Time& time, const ros::Duration& period)
{
if (state_changed_)
{
state_changed_ = false;
ROS_INFO("[Gimbal] Enter POSE");
}

for (auto& it : ctrls_)
{
const int axis = it.first;
auto& ctrl = it.second;
const double joint_pos = ctrl->joint_.getPosition();
double error = 0.0;
if (axis == 1)
error = angles::shortest_angular_distance(joint_pos, cmd_gimbal_.pose_pitch);
else if (axis == 2)
error = angles::shortest_angular_distance(joint_pos, cmd_gimbal_.pose_yaw);

pid_pos_.at(axis)->computeCommand(error, period);
ctrl->setCommand(pid_pos_.at(axis)->getCurrentCmd());
ctrl->update(time, period);
}

odom2gimbal_des_.transform.rotation = odom2gimbal_.transform.rotation;
}

bool Controller::setDesIntoLimit(double& angle, const urdf::JointConstSharedPtr& joint_urdf, bool update,
double current_angle)
{
Expand Down
Loading