本文整理汇总了C++中ros::Subscriber类的典型用法代码示例。如果您正苦于以下问题:C++ Subscriber类的具体用法?C++ Subscriber怎么用?C++ Subscriber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Subscriber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//MAIN
int main(int argc, char** argv)
{
ros::init(argc, argv, "wheel_motor_node"); //Initialize node
ros::NodeHandle n; //Create nodehandle object
sub = n.subscribe("wheel_motor_rc", 1000, callBack); //Create object to subscribe to topic "wheel_motor_rc"
pub = n.advertise<motor_controller::AdaCmd>("adaFruit",1000); //Create object to publish to topic "I2C"
while(pub.getNumSubscribers()==0);//Prevents message from sending when publisher is not completely connected to subscriber.
//ros::Rate loop_rate(10); //Set frequency of looping. 10 Hz
setGPIOWrite(33,1); //Motor enable
while(ros::ok())
{
//Update time
current_time = ros::Time::now();
//Check if interval has passed
if(current_time - last_time > update_rate)
{
//Reset time
last_time = current_time;
if(sub.getNumPublishers() == 0) //In case of loss of connection to publisher, set controller outputs to 0
{
ROS_WARN("Loss of wheel motor controller input!");
leftFrontWheel.setU(0); //Set controller inputs
leftRearWheel.setU(0);
rightRearWheel.setU(0);
rightFrontWheel.setU(0);
}
controlFunction(); //Motor controller function
pub.publish(generateMessage());
}
ros::spinOnce();
}
stopAllMotors();
return 0;
}
示例2: loopRate
MyLittleTurtle(ros::NodeHandle& nodeHandle): m_nodeHandle(nodeHandle)
{
ROS_INFO("Publishing topic...");
m_turtlesimPublisher = m_nodeHandle.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 10);
ROS_INFO("Subscribing to turtlesim topic...");
m_turtlesimSubscriber = m_nodeHandle.subscribe("/turtle1/pose", 10, &MyLittleTurtle::updateTurtleStatus, this);
ROS_INFO("Waiting for turtlesim...");
ros::Rate loopRate(10);
while (ros::ok() && (m_turtlesimPublisher.getNumSubscribers() <= 0 || m_turtlesimSubscriber.getNumPublishers() <= 0))
loopRate.sleep();
checkRosOk_v();
ROS_INFO("Retrieving initial status...");
ros::spinOnce();
ROS_INFO("Initial status: x=%.3f, y=%.3f, z=%.3f", m_status.x, m_status.y, m_status.z);
ROS_INFO("Everything's ready.");
}
示例3: dynamicReconfigureCallback
void dynamicReconfigureCallback(pcl_filters::passthroughConfig &config, uint32_t level)
{
ros::NodeHandle nh("~");
if (axis_.compare(config.filteration_axis.c_str()) != 0)
{
axis_ = config.filteration_axis.c_str();
}
if (min_range_ != config.min_range)
{
min_range_ = config.min_range;
}
if (max_range_ != config.max_range)
{
max_range_ = config.max_range;
}
std::string temp_str = config.passthrough_sub.c_str();
if (!config.passthrough_sub.empty() && passthrough_sub_.compare(temp_str) != 0)
{
sub_.shutdown();
passthrough_sub_ = config.passthrough_sub.c_str();
sub_ = nh.subscribe (passthrough_sub_, 1, cloudCallback);
}
ROS_INFO("Reconfigure Request: %s %f %f",axis_.c_str(), min_range_,max_range_);
}
示例4: camerainfoCb
void camerainfoCb(const sensor_msgs::CameraInfoConstPtr& info_msg)
{
ROS_INFO("infocallback :shutting down camerainfosub");
cam_model_.fromCameraInfo(info_msg);
camera_topic = info_msg->header.frame_id;
camerainfosub_.shutdown();
}
示例5: getNearestObject
bool getNearestObject(hbrs_srvs::GetPose::Request &req, hbrs_srvs::GetPose::Response &res)
{
// if not subscribe to laser scan topic, do it
if(!subscribed_to_topic)
{
sub_scan = nh_ptr->subscribe<sensor_msgs::LaserScan>("/scan", 1, laserScanCallback);
subscribed_to_topic = true;
}
// check if new laser scan data has arrived
scan_received = false;
while(!scan_received)
ros::spinOnce();
// calculate nearest object pose
geometry_msgs::PoseStamped pose;
pose = calculateNearestObject(laser_scan);
res.pose = pose.pose;
// unsubscribe from topic to save computational resources
sub_scan.shutdown();
subscribed_to_topic = false;
return true;
}
示例6: XYOriginCallback
void XYOriginCallback(const topic_tools::ShapeShifter::ConstPtr msg)
{
try
{
const gps_common::GPSFixConstPtr origin = msg->instantiate<gps_common::GPSFix>();
xy_wgs84_util_.reset(
new swri_transform_util::LocalXyWgs84Util(
origin->latitude,
origin->longitude,
origin->track,
origin->altitude));
origin_sub_.shutdown();
return;
}
catch (...) {}
try
{
const geometry_msgs::PoseStampedConstPtr origin = msg->instantiate<geometry_msgs::PoseStamped>();
xy_wgs84_util_.reset(
new swri_transform_util::LocalXyWgs84Util(
origin->pose.position.y, // Latitude
origin->pose.position.x, // Longitude
0.0, // Heading
origin->pose.position.z)); // Altitude
origin_sub_.shutdown();
return;
}
catch(...) {}
try
{
const geographic_msgs::GeoPoseConstPtr origin = msg->instantiate<geographic_msgs::GeoPose>();
xy_wgs84_util_.reset(
new swri_transform_util::LocalXyWgs84Util(
origin->position.latitude,
origin->position.longitude,
tf::getYaw(origin->orientation),
origin->position.altitude));
origin_sub_.shutdown();
return;
}
catch(...) {}
ROS_ERROR_THROTTLE(1.0, "Unsupported message type received for local_xy_origin.");
}
示例7: jointCallback
void jointCallback(const sensor_msgs::JointState & msg){
ROS_INFO("RECEIVED JOINT VALUES");
if(itHappened){
sub.shutdown();
cout<<"not again"<<endl;
return;
}
if (msg.name.size()== 6 ) {
itHappened=true;
for (int i=0;i<6;i++){
joint_pos[i] = msg.position[i];
name[i] = msg.name[i];
// cout<<" , "<<name[i]<<":"<<joint_pos[i];
}
sub.shutdown();
}
}
示例8: cam_info_callback
void cam_info_callback(const sensor_msgs::CameraInfo &msg)
{
tgCamParams = TomGine::tgCamera::Parameter(msg);
ROS_INFO("Camera parameters received.");
camera_info = msg;
need_cam_init = false;
cam_info_sub.shutdown();
}
示例9: wallDetectCB
void wallDetectCB(std_msgs::Bool)
{
ROS_INFO("Drag Race Controller got wall.");
racecar_set_speed(0);
race_end_subscriber.shutdown();
system("rosnode kill iarrc_lane_detection &\n");
system("rosnode kill drag_race_end_detector &\n");
exit(0);
}
示例10: unsubscribe
void unsubscribe()
{
if (use_indices_) {
sub_input_.unsubscribe();
sub_indices_.unsubscribe();
}
else {
sub_.shutdown();
}
}
示例11: stop
void stop()
{
if (!running_) return;
cam_->stop(); // Must stop camera before streaming_pub_.
poll_srv_.shutdown();
trigger_sub_.shutdown();
streaming_pub_.shutdown();
running_ = false;
}
示例12: stoplightCB
void stoplightCB(std_msgs::Bool)
{
ROS_INFO("Drag Race Controller got stoplight.");
racecar_set_speed(14);
//racecar_set_speed(0);
stoplight_subscriber.shutdown();
system("rosnode kill stoplight_watcher &\n");
system("roslaunch iarrc_launch lane_detection.launch &\n");
system("roslaunch iarrc_launch race_end_detector.launch &\n");
race_end_subscriber = nh->subscribe(race_end_topic, 1, wallDetectCB);
}
示例13: pause
//service callback:
//pause the topic model
void pause(bool p){
if(p){
ROS_INFO("stopped listening to words");
word_sub.shutdown();
}
else{
ROS_INFO("started listening to words");
word_sub = nh->subscribe("words", 10, words_callback);
}
rost->pause(p);
paused=p;
}
示例14: stop
bool stop(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
{
if(subscribed_to_topic)
{
sub_scan.shutdown();
subscribed_to_topic = false;
}
continues_mode_enabled = false;
ROS_INFO("nearest object detector DISABLED");
return true;
}
示例15: stop
bool
stop (camera_srv_definitions::start_tracker::Request & req,
camera_srv_definitions::start_tracker::Response & response)
{
#ifdef USE_PCL_GRABBER
if(interface.get())
interface->stop();
#else
camera_topic_subscriber_.shutdown();
#endif
if (!camtracker.empty())
camtracker->stopObjectManagement();
return true;
}