Calling a service in C++ without write it on terminal
I wanna clear my turtlesim path when I press a specific button of my joystick, like when I write it on terminal: rosservice call clear .
Afterwards, I wanna do the same idea but changing the background like rosparam set background-r 150
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>
#include <ros/service.h>
class TeleopTurtle
{
public:
TeleopTurtle();
private:
void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
ros::NodeHandle nh_;
int linear_, angular_;
double l_scale_, a_scale_;
ros::Publisher vel_pub_;
ros::Subscriber joy_sub_;
};
TeleopTurtle::TeleopTurtle():
linear_(1),
angular_(2)
{
nh_.param("axis_linear", linear_, linear_);
nh_.param("axis_angular", angular_, angular_);
nh_.param("scale_angular", a_scale_, a_scale_);
nh_.param("scale_linear", l_scale_, l_scale_);
vel_pub_ = nh_.advertise<geometry_msgs::Twist>("turtle1/cmd_vel", 1);
joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 10, &TeleopTurtle::joyCallback, this);
}
void TeleopTurtle::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
geometry_msgs::Twist twist;
twist.linear.x = l_scale_*joy->axes[linear_];
twist.angular.z = a_scale_*joy->axes[angular_];
vel_pub_.publish(twist);
if (joy->buttons[2] == 1)
{
//ros::service::call(clear); // Call service: rosservice call clear
}
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "teleop_turtle");
TeleopTurtle teleop_turtle;
ros::spin();
}
All this is possible, but what is your question?
Calling a ros service (rosservice call clear) in C++ without write it on terminal when i press a specific button