本文整理汇总了C++中ros::ServiceClient类的典型用法代码示例。如果您正苦于以下问题:C++ ServiceClient类的具体用法?C++ ServiceClient怎么用?C++ ServiceClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: plotSummary
bool plotSummary(ros::ServiceClient& sum_client)
{
PlanningSummary planning_sum;
if (!sum_client.call(planning_sum))
{
return false;
}
unsigned int cols = planning_sum.response.score_labels.size();
for (unsigned int i = 0; i < planning_sum.response.score_labels.size(); i++)
{
cout << planning_sum.response.score_labels[i] << "\t";
}
cout << endl;
for (unsigned int i = 0; i < planning_sum.response.score_values.size(); i++)
{
if (i % cols == 0)
{
cout << i / cols << ": ";
}
cout << planning_sum.response.score_values[i];
cout << "\t";
if (i % cols == cols - 1)
{
cout << endl;
}
}
return true;
}
示例2: heartMonitor
void heartMonitor(ros::NodeHandle n, ros::ServiceClient client, estop_control::estopSignal srv)
{
time(&now); // get current time; same as: now = time(NULL)
if(heartbeat == true)
{
heartbeat = false;
ROS_INFO("beating");
previousTime = now;
}
if(difftime(now, previousTime) > 1) // 1 second delay
{
ROS_INFO("heart stopped"); //estop
// ros::ServiceClient client = n.serviceClient<estop_control::estopSignal>("estop_control");
// estop_control::estopSignal srv;
srv.request.message = 1;
if (client.call(srv))
{
ROS_INFO("Recieved handshake: %d", (bool)srv.response.handshake);
}
else
{
ROS_ERROR("Failed to call service estop_control");
}
//client.shutdown();
}
}
示例3: map
TestKeyframeExtraction(ros::NodeHandle & nh) :
action_client("/cloudbot1/turtlebot_move", true), map(
new keyframe_map) {
pointcloud_pub = nh.advertise<pcl::PointCloud<pcl::PointXYZRGB> >(
"/cloudbot1/pointcloud", 1);
servo_pub = nh.advertise<std_msgs::Float32>(
"/cloudbot1/mobile_base/commands/servo_angle", 3);
keyframe_sub = nh.subscribe("/cloudbot1/keyframe", 10,
&TestKeyframeExtraction::chatterCallback, this);
update_map_service = nh.serviceClient<rm_localization::UpdateMap>(
"/cloudbot1/update_map");
clear_keyframes_service = nh.serviceClient<std_srvs::Empty>(
"/cloudbot1/clear_keyframes");
set_camera_info_service = nh.serviceClient<sensor_msgs::SetCameraInfo>(
"/cloudbot1/rgb/set_camera_info");
std_srvs::Empty emp;
clear_keyframes_service.call(emp);
}
示例4: anyBrickCallback
void anyBrickCallback(std_msgs::Bool msg)
{
// Fetch robot position
kuka_rsi::getConfiguration getQObj;
// Call service
if(!_serviceGetConf.call(getQObj))
printConsole("Failed to call the 'serviceKukaGetConfiguration'");
// Get information
bool same = true;
for(int i=0; i<6; i++)
{
if(fabs(getQObj.response.q[i]*DEGREETORAD - _qIdle[i]) > 0.1)
{
same = false;
break;
}
}
_anyBricksMutex.lock();
_anyBricks = msg.data;
_anyBricksMutex.unlock();
_qMutex.lock();
_positionQIdle = same;
_qMutex.unlock();
}
示例5: ubicacionCallback
void ubicacionCallback(const vrep_common::ObjectGroupData msgUbicacionPatas)
{
for(int k=1; k<Npatas+1; k++){
ubicacionRobot.coordenadaPata_x[k-1]=msgUbicacionPatas.floatData.data[0+k*Npatas/2];
ubicacionRobot.coordenadaPata_y[k-1]=msgUbicacionPatas.floatData.data[1+k*Npatas/2];
ubicacionRobot.coordenadaPata_z[k-1]=msgUbicacionPatas.floatData.data[2+k*Npatas/2];
//-- Transformacion de trayectoria a Sistema de Pata
srv_Trans_MundoPata.request.modo=Mundo_Pata;
srv_Trans_MundoPata.request.Npata=k-1;
srv_Trans_MundoPata.request.x_S0=ubicacionRobot.coordenadaPata_x[k-1];
srv_Trans_MundoPata.request.y_S0=ubicacionRobot.coordenadaPata_y[k-1];
srv_Trans_MundoPata.request.z_S0=ubicacionRobot.coordenadaPata_z[k-1];
srv_Trans_MundoPata.request.x_UbicacionRob=ubicacionRobot.coordenadaCuerpo_x;
srv_Trans_MundoPata.request.y_UbicacionRob=ubicacionRobot.coordenadaCuerpo_y;
srv_Trans_MundoPata.request.theta_Rob=ubicacionRobot.orientacionCuerpo_yaw;
if (client_Trans_MundoPata.call(srv_Trans_MundoPata))
{ ubicacionRobot.coordenadaPataSistemaPata_x[k-1] = srv_Trans_MundoPata.response.x_Pata;
ubicacionRobot.coordenadaPataSistemaPata_y[k-1] = srv_Trans_MundoPata.response.y_Pata;
ubicacionRobot.coordenadaPataSistemaPata_z[k-1] = srv_Trans_MundoPata.response.z_Pata;
// ROS_INFO("Servicio motores: q1=%.3f; q2=%.3f; q3=%.3f\n", _q1, _q2, _q3);
} else {
ROS_ERROR("Nodo6:[%d] servicio de Trans_MundoPata no funciona\n",k-1);
// return;
}
// ROS_INFO("Nodo6: pata[%d], x=%.3f, y=%.3f",k-1,ubicacionRobot.coordenadaPata_x[k-1],ubicacionRobot.coordenadaPata_y[k-1]);
}
infoPatas = true;
}
示例6: startConveyerBelt
void startConveyerBelt(bool dir = false)
{
rc_plc::StartConv obj;
obj.request.direction = dir;
if(!_serviceStart.call(obj))
printConsole("Failed to call the 'serviceStartConveyer'");
}
示例7: sub1_callback
/**
* @brief Callback functions for datalink routing, channel 1
*
*/
void sub1_callback(const uav_control::DFrame msg)
{
// message from GCS, to be relayed to quadcopter
if(msg.target_id != SYSID){
uav_control::datalink_send ss;
ss.request.source_id = msg.source_id;
ss.request.target_id = msg.target_id;
ss.request.route = msg.route;
ss.request.len = msg.len;
int i;
for(i=0; i<msg.len; i++)
ss.request.payload[i] = msg.payload[i];
if(client_sub1.call(ss)){
switch(ss.response.err){
case 0: //ROS_INFO("successful");
break;
case 1: ROS_ERROR("relay error: invalid channel");
break;
case 2: ROS_ERROR("relay error: channel not initialized");
break;
case 3: ROS_ERROR("relay error: sending failed");
break;
default: ROS_ERROR("relay error: unknown failure");
break;
}
}
}
}
示例8: state_callback
/**
* @brief Report to GCS arming / disarming state of the uav
*/
void state_callback(const mavros_msgs::State msg){
uav_control::datalink_send ss;
ss.request.source_id = sysid;
ss.request.target_id = 0x00;
ss.request.route = 2;
ss.request.len = 4 + msg.mode.length() + 1;
ss.request.payload[0] = 29;
ss.request.payload[1] = msg.connected ? 'T' : 'F';
ss.request.payload[2] = msg.armed ? 'T' : 'F';
ss.request.payload[3] = msg.guided ? 'T' : 'F';
sprintf((char*)&(ss.request.payload[4]), "%s", msg.mode.c_str());
if(client.call(ss)){
switch(ss.response.err){
case 0:
break;
case 1: ROS_ERROR("uav_stat_monitor sending failed: invalid channel");
break;
case 2: ROS_ERROR("uav_stat_monitor sending failed: channel not initialized");
break;
case 3: ROS_ERROR("uav_stat_monitor sending failed: sending failed");
break;
default: ROS_ERROR("uav_stat_monitor sending failed: unknown failure");
break;
}
}
}
示例9: getFirstWayPoint
bool CutterSteering::getFirstWayPoint()
{
if (got_waypoint_)
return true;
waypoint_srv_.request.increment = false;
if(waypoint_client_.call(waypoint_srv_))
{
if (waypoint_srv_.response.pointsLeft > 0)
{
got_waypoint_ = true;
ROS_INFO("Got first waypoint");
initialX = map_pose_.position.x;
initialY = map_pose_.position.y;
ROS_INFO("Recorded initial position.");
last_waypoint_ = cutter_msgs::WayPoint();
target_waypoint_ = waypoint_srv_.response.currWayPoint;
next_waypoint_ = waypoint_srv_.response.nextWayPoint;
initial_align = true;
return true;
}
}
return false;
}
示例10: singleShotService
bool singleShotService(blort_ros::EstimatePose::Request &req,
blort_ros::EstimatePose::Response &resp)
{
if(lastImage.use_count() < 1 && lastCameraInfo.use_count() < 1)
{
ROS_ERROR("Service called but there was no data on the input topics!");
return false;
} else {
ROS_INFO("Singleshot service has been called with a timeout of %f seconds.", time_to_run_singleshot);
results.clear();
if(parent_->tracker == 0)
{
parent_->tracker = new blort_ros::GLTracker(*lastCameraInfo, parent_->root_, true);
parent_->recovery_client = parent_->nh_.serviceClient<blort_ros::RecoveryCall>("/blort_detector/poseService");
} else {
parent_->tracker->reset();
}
parent_->tracker->setPublisMode(blort_ros::TRACKER_PUBLISH_GOOD);
parent_->tracker->setVisualizeObjPose(true);
blort_ros::SetCameraInfo camera_info;
camera_info.request.CameraInfo = *lastCameraInfo;
if(!detector_set_caminfo_service.call(camera_info))
ROS_ERROR("blort_tracker failed to call blort_detector/set_camera_info service");
double start_secs = ros::Time::now().toSec();
while(ros::Time::now().toSec()-start_secs < time_to_run_singleshot)
{
ROS_INFO("Remaining time %f", time_to_run_singleshot+start_secs-ros::Time::now().toSec());
parent_->imageCb(lastImage);
if(parent_->tracker->getConfidence() == blort_ros::TRACKER_CONF_GOOD)
{
// instead of returning right away let's store the result
// to see if the tracker can get better
results.push_back(parent_->tracker->getDetections()[0]);
} else if(parent_->tracker->getConfidence() == blort_ros::TRACKER_CONF_LOST)
{
results.clear();
}
}
// we are out of the service call now, the results will be published
inServiceCall = false;
if(!results.empty())
{
//convert results to a tf style transform and multiply them
//to get the camera-to-target transformation
resp.Pose = pal_blort::blortPosesToRosPose(parent_->tracker->getCameraReferencePose(),
results.back());
//NOTE: check the pose in vec3 location + mat3x3 rotation could be added here
// if we have any previous knowledge of the given scene
ROS_INFO_STREAM("PUBLISHED POSE: \n" << resp.Pose.position << "\n" <<
pal_blort::quaternionTo3x3cvMat(resp.Pose.orientation) << "\n");
return true;
} else {
//if the time was not enough to get a good detection, make the whole thing fail
return false;
}
}
}
示例11: set_servo_reference
/*!
* \brief set the position, speed and acceleration for a servo
* \param index servo index
* \param engage whether to energise the servo
* \param position reference position for the servo
* \param speed reference speed for the servo
* \param acceleration reference acceleration for the servo
*/
void set_servo_reference(
int index,
bool engage,
float position,
float speed,
float acceleration)
{
phidgets::servo_reference srv;
srv.request.index = index;
srv.request.engage = engage;
srv.request.position = position;
srv.request.speed = speed;
srv.request.acceleration = acceleration;
srv.response.ack = 0;
if (client_servo_reference.call(srv)) {
if ((int)srv.response.ack == 1) {
ROS_INFO("Changed servo %d reference %.2f",
index, position);
}
else {
ROS_INFO("Returned %d", (int)srv.response.ack);
}
}
else {
ROS_ERROR("Failed to call service servo_reference");
}
}
示例12: resetOctomap
/* Publishes an empty scene to reset/refresh it */
void resetOctomap(){
cout << "Clearing Octomap !" << endl;
moveit_msgs::PlanningScene planning_scene;
moveit_msgs::GetPlanningScene scene_srv;
scene_srv.request.components.components = scene_srv.request.components.ALLOWED_COLLISION_MATRIX +
scene_srv.request.components.LINK_PADDING_AND_SCALING +
scene_srv.request.components.OBJECT_COLORS +
scene_srv.request.components.OCTOMAP +
scene_srv.request.components.ROBOT_STATE +
scene_srv.request.components.ROBOT_STATE_ATTACHED_OBJECTS +
scene_srv.request.components.SCENE_SETTINGS +
scene_srv.request.components.TRANSFORMS +
scene_srv.request.components.WORLD_OBJECT_GEOMETRY +
scene_srv.request.components.WORLD_OBJECT_NAMES;
if(client_get_scene_.call(scene_srv)){
moveit_msgs::PlanningScene planning_scene = scene_srv.response.scene;
planning_scene.world.octomap.octomap.data.clear();
ros::WallDuration sleep_time(0.5);
//planning_scene.is_diff = true;
planning_scene_publisher.publish(planning_scene);
sleep_time.sleep();
}
}
示例13: changeDirConveyerBelt
void changeDirConveyerBelt(bool dir) // true = reverse
{
rc_plc::ChangeDirection obj;
obj.request.direction = dir;
if(!_serviceChangeDir.call(obj))
printConsole("Failed to call the 'serviceChangeDirConveyer'");
}
示例14: pick
/*
Function to pick up an object named <object_name>
*/
void pick(std::string object_name)
{
world_model_srv.request.base_frame = "gripperbot_base";
world_model_srv.request.target_frame = object_name;
if(world_model_client.call(world_model_srv))
{
if(world_model_srv.response.success)
{
if(world_model_srv.response.pose.position.x < 0)
return;
if(world_model_srv.response.pose.position.z < 0)
world_model_srv.response.pose.position.z = -world_model_srv.response.pose.position.z;
movegripperbot(world_model_srv.response.pose.position.x, world_model_srv.response.pose.position.y, world_model_srv.response.pose.position.z+0.1);
opengripper();
movegripperbot(world_model_srv.response.pose.position.x, world_model_srv.response.pose.position.y, world_model_srv.response.pose.position.z);
closegripper();
movegripperbot(world_model_srv.response.pose.position.x, world_model_srv.response.pose.position.y, world_model_srv.response.pose.position.z+0.1);
}
else
{
ROS_ERROR("Transform between object and gripperbot_base doesnt exist");
}
}
else
{
ROS_ERROR("Failed to call service /world_model/get_transform");
}
}
示例15: getBricks
std::vector<Brick> getBricks()
{
std::vector<Brick> retVec;
rc_vision::getBricks obj;
if(!_serviceGetBricks.call(obj))
{
printConsole("Failed to call the 'serviceGetBricks'");
}
else
{
for(unsigned int i=0; i<obj.response.size.size(); i++)
{
Brick brick;
brick.color = obj.response.color[i];
brick.posX = obj.response.posX[i];
brick.posY = obj.response.posY[i];
brick.size = obj.response.size[i];
brick.theta = obj.response.theta[i];
retVec.push_back(brick);
}
}
return retVec;
}