ros introductory tutorial (eight) - client library: rospy (on)

Client Library

This concept concept and our understanding of the API is very similar. Offer ROS is essentially a programming library. For example: the establishment node, announced that invoke the service. It encapsulates the underlying operational processes, help us to write code to call.

The client library has several versions: roscpp, rospy, roslisp

The top two talk about the roscpp, this lecture will be mentioned rospy. rospy interfaces including the Node, Topic, Service, Parameter, Time categories.

rospy

rospy-Node-related

Function
init_node (name) # Registration and initialize node

import rospy 
rospy.init_node('my_node') # 没有返回值

MasterProxy

  • get_master () # get a handle master of

bool

  • is_shutdown () # Returns whether closed
  • on_shutdown (fn) # call the function fn when the node is closed

str

  • get_node_uri () # returns the node URI
  • get_name () # returns the full name of this node
  • get_namespace () # Returns the namespace of the current node
rospy-Topic related

Function
[[str1, str2]] get_published_topics () # returns all topic names are being released (str1) and type (str2)

Message

  • wait_for_message (topic, topic_type, time_out = None) # wait for the specified topic of a msg

  • spin () # trigger the topic of service or treatment, will be blocked until the close

Publisher class

  • __init __ (self, name, data_class, queue_size = None) # Constructor
  • publish (self, msg) # member functions to post a message
  • unregister (self) # member function to stop publishing the
    case:
pub = rospy.Publisher('topic_name','topic_type',queue_size=None) #size=None相当于同步通信,大于零会为异步通信
pub.publish(msg)

Subscriber class

  • __init __ (self, name, data_class, call_back = None, queue_size = None) # Constructor
  • unregister (self) # member functions unsubscribe
rospy-Service-related

function

wait_for_service (service, timeout = None) # blocked until the service is available

Service category -> server-related
_init_ (self, name, service_class, handler) # constructor service
shutdown (self) # member functions shut down service

handler case:

def handler(req):
    pass
    return res #只传入请求,只传出响应

ServiceProxy class > client related -
requestor __init __ (self, name, service_class ) # constructor and services

Response

  • call (self, * args, ** kwds) # call service
  • __call __ (self, * args, ** kwds) # call service
client = ServiceProxy(...) //构造函数
client.call(req)
#或者
resp = client(req)
rospy-Param-related

function

XmlRpcLegalValue

  • get_param (param_name, default = _unspecified) # get the value of the parameter

[str]

  • get_param_names () # Get the name of the parameter
  • set_param (param_name, param_value) # set the value of the parameter
  • delete_param (param_name) # delete parameters

bool

  • has_param (param_name) # parameter exists on the server parameters

str

  • search_param () # search parameters
rospy-Time-related

Class Time -> means time

__init __ (self, secs = 0 , nsecs = 0) # Constructor
Time now () # static method returns the current time Time object

case:

rospy.Time(secs = 1, nsecs = 0)
# or
rospy.Time.now()

Duration class -> means a period of time
__init __ (self, secs = 0 , nsecs = 0) # constructor second and nanosecond

Note : subtraction operation time, the results may vary in time, not the time and two addition and subtraction.

function

Time

  • get_rostime () # Time current target time

float

  • get_time () # returns the current time, it returns a float in seconds
  • sleep (duration) # suspend execution

Rate class
__init __ (self, frequency) # constructor
sleep (self) # hangs once considered rate.sleep () time

Time

  • remaining (self) # member functions remaining sleep time

Please indicate the source.
This paper summarizes the Chinese University of MOOC "Android OS Getting Started"
link: Link .
Pictures from the video capture program

Published 43 original articles · won praise 20 · views 1471

Guess you like

Origin blog.csdn.net/Chen_2018k/article/details/104346359