An Objective-C library for ROSBridge that uses WebSockets to communicate with Robot Operating System (ROS).
For a more detailed example than this reference document, please read my blog post:
RBManager provides a wrapper for the different ROS functionality calls:
- Socket Rocket websockets library
- iOS 7 SDK
- Xcode 5
- The iPhone simulator works, but if you want to use a device, you'll also need to be a member of the iOS developer program
RBManager behaves as a singleton, so only one manager is required. Use
Connect to an ROSBridge instance by calling
-(void)connect:(NSString*)socketHost and disconnect later by calling
Assign a delegate to RBManager and implement the following methods to be alerted when the socket changes state. RBManager also posts a notification to
-(void)managerDidConnect:(RBManager*)manager; -(void)manager:(RBManager*)manager didFailWithError:(NSError*)error; -(void)manager:(RBManager*)manager didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
Messages are a core component of ROS and RBManager. They are used by publishers and subscribers. Inherit from an RBMessage object and implement the
-(NSDictionary*)publish method to generate the data required for publishing.
Message objects should use Foundation objects (ie. NSNumber and NSString), but can also use nested message types. Some of the common message types are defined already and more will be added over time.
Subscriber objects are created by calling
-(RBSubscriber*)addSubscriber:(NSString*)topic responseTarget:(id)subscriberObject selector:(SEL)subscriberSelector messageClass:(Class)messageClass;
- topic -- ROS topic to subscribe to
- responseObject -- object that receives the result
- subscriberSelector -- the method called when the result is received
- messageClass -- the RBMessage compatible class that will be returned
Subscribers respond to the same properties as the ROSBridge protocol specification.
[[RBManager defaultManager] addSubscriber:@"/turtlesim/pose" responseObject:self selector:@selector(poseMessageReceived:) messageClass:[PoseMessage class]]
All subscribers are automatically subscribed to when a connection is opened. To un/subscribe directly, call
[subscriber subscribe] or
Publisher objects are created by calling
- topic -- ROS topic to send data to
- messageType -- the type of ROS message the publisher expects
[[RBManager defaultManager] addPublisher:@"/turtle1/cmd_vel" messageType:@"geometry_msgs/Twist"]
Like subscribers, publishers are also advertised automatically when a socket is opened, but you can un/advertise directly by calling
[publisher advertise] and
When you want to publish a new message, create a message object and send to
Service call objects are created in a similar fashion. Call
-(RBServiceCall*)makeServiceCall:(id)serviceCallObject selector:(SEL)serviceSelector name:(NSString*)service
to create an object
- serviceCallObject -- the object that will receive a response
- serviceSelector -- the method that will be called when a response is available
- name -- the ROS service that will be called
No parameters are required but they can optionally be attached by calling
[serviceCallObject setArgs:array] or
[serviceCallObject send] when you want to send the call.
Service Call Wrappers
RBManager wraps set/get parameter service calls to make those easier.
-(RBServiceCall*)setParam:(NSString*)name value:(NSString*)value -(RBServiceCall*)getParam:(NSString*)name object:(id)object selector:(SEL)responseSelector
Both methods generate a standard RBServiceCall object.
Please keep in mind that this library is very new. I'll be testing it regularly, particularly against the turtle sim. Create an issue in github or email me directly -- w [at] wesg [dot] ca