Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enable charging service #47

Merged
merged 1 commit into from
Jul 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class SlateBase
// Motor status service server
ros::ServiceServer srv_motor_torque_status_;

// Set charge enable service server
ros::ServiceServer srv_enable_charing_;

// Name of odom frame
std::string odom_frame_name_;

Expand Down Expand Up @@ -147,6 +150,16 @@ class SlateBase
std_srvs::SetBool::Request & req,
std_srvs::SetBool::Response & res);

/**
* @brief Process incoming enable charing service request
* @param req Service request containing desired desired charing enable status
* @param res[out] Service response containing a success indication and a message
* @return True if service succeeded, false otherwise
*/
bool enable_charing_callback(
std_srvs::SetBool::Request & req,
std_srvs::SetBool::Response & res);

/**
* @brief Wrap angle
* @param angle Angle to wrap in radians
Expand Down
21 changes: 21 additions & 0 deletions interbotix_ros_slate/interbotix_slate_driver/src/slate_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ SlateBase::SlateBase(ros::NodeHandle * node_handle)
&SlateBase::motor_torque_status_callback,
this);

srv_enable_charing_ = node.advertiseService(
"enable_charging",
&SlateBase::enable_charing_callback,
this);

std::string dev;
if (!base_driver::chassisInit(dev)) {
ROS_FATAL("Failed to initialize base.");
Expand Down Expand Up @@ -168,6 +173,22 @@ bool SlateBase::motor_torque_status_callback(
return res.success;
}

bool SlateBase::enable_charing_callback(
std_srvs::SetBool::Request & req,
std_srvs::SetBool::Response & res)
{
res.success = base_driver::setCharge(req.data);
std::string enabled_disabled = req.data ? "enable" : "disable";
if (res.success) {
res.message = "Successfully " + enabled_disabled + "d charging.";
ROS_INFO(res.message.c_str());
} else {
res.message = "Failed to " + enabled_disabled + " charging.";
ROS_ERROR(res.message.c_str());
}
return res.success;
}

float SlateBase::wrap_angle(float angle)
{
if (angle > M_PI) {
Expand Down