ROS基础 | API函数

1. ros::init()

1.1 ros::init()

brief:ROS initialization function. This function will parse any ROS arguments (e.g., topic name remappings), and will consume them (i.e., argc and argv may be modified as a result of this call). Use this version if you are using the NodeHandle API

1.2 ros::start()

brief: Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc loops,connects to internal subscriptions like /clock, starts internal service servers, etc.).Usually unnecessary to call manually, as it is automatically called by the creation of the first NodeHandle if the node has not already been started. If you would like to prevent the automatic shutdown caused by the last NodeHandle going out of scope, call this before any NodeHandle has been created (e.g. immediately after init())

2 node_handle

2.1 subscribe

template<class M, class T>
Subscriber subscribe(const std::string& topic, 
					 uint32_t queue_size, 
					 void(T::*fp)(M), 
					 T* obj, 
                     const TransportHints& transport_hints = TransportHints())
 /**
   * brief: Subscribe to a topic, version for class member function with bare pointer
   * param M [template] M here is the callback parameter type (e.g. const boost::shared_ptr<M const>& or const M&), \b not the message type, and should almost always be deduced
   * param topic Topic to subscribe to
   * param queue_size Number of incoming messages to queue up for
   * processing (messages in excess of this queue capacity will be
   * discarded).
   * param fp Member function pointer to call when a message has arrived
   * param obj Object to call fp on
   * param transport_hints a TransportHints structure which defines various transport-related options
   */                     

cv_bridge

CvImageConstPtr toCvShare(const sensor_msgs::ImageConstPtr& source,
                          const std::string& encoding = std::string());
/**
 * brief Convert an immutable sensor_msgs::Image message to an OpenCV-compatible CvImage, sharing
 * the image data if possible.
 *
 * If the source encoding and desired encoding are the same, the returned CvImage will share
 * the image data with \a source without copying it. The returned CvImage cannot be modified, as that
 * could modify the \a source data.
 *
 * \param source   A shared_ptr to a sensor_msgs::Image message
 * \param encoding The desired encoding of the image data, one of the following strings:
 * */                                          

【1】 ros::NodeHandle::param()

template<typename T >
/*
 *@brief:从参数服务器获取参数,获取失败使用默认值
 *@param: param_name  索取参数的关键词
 *@param: param_val   参数的赋值对象
 *@param:default_val 默认值
 */
bool ros::NodeHandle::param	(const std::string & param_name,
							 T & param_val,
							 const T & default_val 
							)const

【2】geometry_msgs::PoseStamped

/*
target_pose 的类型为geometry_msgs/PoseStamped 
 A Pose with reference coordinate frame and timestamp
Header header
Pose pose
Record PoseStamped := { _header : Header.Header; _pose : Pose.Pose}
*/
//-------------------- [demo]--------------------//
geometry_msgs/PoseStamped target_pose
//--step1: 构造header
target_pose.header.seq = 0;
target_pose.header.stamp =ros::Time::now();//如果有问题就使用Time(0)获取时间戳,确保类型一致
target_pose.header.frame_id = "map";
//--step2:  构造pose
target_pose.pose.position.x = x1;
target_pose.pose.position.y = y1;
target_pose.pose.position.z = 0.0;
target_pose.pose.orientation.x = 0.0;
target_pose.pose.orientation.y = 0.0;
target_pose.pose.orientation.w = 1.0;

参考blog:
[1] : Subscribe的第四个参数用法

[2] :ros wiki

[3] :glog的编译和使用

[4] : 机器人操作系统ROS:从入门到放弃(三) 发布接收不同消息2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器人坐标变化的基本原理是通过传感器获得机器人当前的姿态信息,包括位置和方向等,然后根据机器人移动的方式和所处的环境,计算出机器人在新坐标系下的位置和方向信息。 在ROS中,可以使用tf库提供的函数来实现机器人坐标变换。其中,最常用的是tf.TransformBroadcaster和tf.TransformListener类的API函数。tf.TransformBroadcaster可以将机器人的坐标变换广播给其他节点,而tf.TransformListener则可以监听其他节点广播的坐标变换信息并进行相应的处理。 例如,可以使用tf.TransformBroadcaster的sendTransform函数将机器人在map坐标系下的姿态信息广播出去: ``` import tf br = tf.TransformBroadcaster() br.sendTransform((x, y, z), tf.transformations.quaternion_from_euler(roll, pitch, yaw), rospy.Time.now(), "robot", "map") ``` 其中,(x, y, z)是机器人在map坐标系下的位置,tf.transformations.quaternion_from_euler(roll, pitch, yaw)是机器人在map坐标系下的旋转信息,"robot"是机器人的坐标系名称,"map"是机器人所处的坐标系名称。 而tf.TransformListener的lookupTransform函数可以获取其他节点广播的坐标变换信息: ``` import tf listener = tf.TransformListener() (trans, rot) = listener.lookupTransform("map", "robot", rospy.Time(0)) ``` 其中,"map"和"robot"分别是要查询的坐标系名称,rospy.Time(0)表示要获取最新的坐标变换信息。该函数会返回机器人在map坐标系下的位置信息trans和旋转信息rot。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值