1.5.1 • Published 4 years ago

@ifollow/ros-client v1.5.1

Weekly downloads
21
License
MIT
Repository
github
Last release
4 years ago

Roslibjs Client

This is a wrapper around the roslibjs package aiming to improve shortcomings of the original roslib package by introducing a fluent API as well as some useful error and fault handling mechanisms.

For the official roslibjs repository please head to https://github.com/RobotWebTools/roslibjs

It includes documentation about interacting with the robot.

Main Features

  • Fluent API
  • Automatic connection recovery
  • Reconnect support for topics

Documentation

Establishing a reliable connection with ROS is one of the main objectives of this library. It is, also, quite simple and straightforward. Just instantiate the library like so:

var RosClient = require("roslibjs-client"); // This is not necessary in the browser
var client = new RosClient({
	url: "ws://192.168.0.11:9090"
});

Once you instantiate the client, it will connect to the said URL and stay connected. If the connection drops, it will try to reconnect every 5 seconds. You can change this interval by passing an additional reconnectInterval option in milliseconds. It is set to 5000 by default.

1. Listening to Topics

Listening to ROS topics is much more reliable and efficient with this library because the handlers will tolerate connection drops. If your app gets disconnected from ROS, all the topics you have subscribed to are still stored by Roslibjs Client and once the connection is gained, it will instantly resubscribe to all the topics you want to listen.

You also don't have to worry about subscribing to a certain Topic multiple times. Behind the scenes, Roslibjs Client will always subscribe to a Topic once no matter how many handlers you attach to it.

To start listening to a topic simply do:

var listener = client.topic.subscribe(topic_name, message_type, function(message) {
	// Here you can handle the message
});

To stop listening to it, simply call listener.dispose()

And that's all there is to it, really. This handler will continue to work even after you lose and gain connectivity.

2. Publishing a Topic

To publish a message over a ROS Topic run simply:

client.topic.publish(topic_name, message_type, payload);

3. Service Calls

To make a service call run the following:

client.service.call(service_name, service_type, payload);

This returns a promise that will resolve when the service call is finished. Using that promise you can retrieve the response.

4. Action Calls

To make a call run the following:

var listener = client.action.send(name, action, payload, timeout, feedback_callback, timeout_callback, result_callback);

feedback_callback is a function to receive feedbacks about currently being performed actions

timeout_callback is a function to receive timeout events based on passed timeout parameter

result_callback is a function to receive final result of executed group of actions

To cancel the action, simply call listener.cancel() and it will stop the action and unsubscribe from feedback and result callbacks

5. Events

RosClient extends EventEmitter2 and offers two simple events that you can listen to:

  1. connected will be fired once when RosClient connects to the target.
  2. disconnected will be fired once the connection is lost.

You can easily listen to these events like so:

client.on("connected", function() {
	alert("Connection established!");
});

Interacting with the robot

Main features

  • Request a robot
  • Send a group of actions to a robot
  • Groups are either stackable or overwritable
  • An action can be mandatory or optional, meaning it has to succeed to continue the following actions or it can fail
  • If action is mandatory and fails, it will retry a specific number of times

Request a robot

This feature is a synchronous service:

  • Availability: returns robot name (for ex. ilogistics_2_0001)
  • No avaibility: returns 'None'

It requires to connect to the central server as follow:

var client = new RosClient({
	url: "ws://ifollow-server:9090"
});

client.service.call(
	"/get_robot_for_picking", 
	"ifollow_ll_msgs/AssignRobotGlobalStateMachine", 
	{})

Retrieving a robot name means client can now connect to the robot as follow:

var client = new RosClient({
	url: "ws://ilogistics-2-0001:9090"
});

Be aware that retrieved robot name is ilogistics_2_0001 and url uses ilogistics-2-0001

Send actions to the robot

This feature is an asynchronous service, for which you can use the Promise.then method to get the result as follow:

client.action.send(
	'/task_manager/picking_care_server', 
	'ifollow_ll_msgs/TaskManagerOrderAction', 
	{
		label: 'A random name you choose',
		overwrite: true,
		actions: [
			{ label: '', order: '', optional_success: false, retry_count: 0},
			...
			!!!! See parameters definition below !!!
		]
	},
	undefined, // if not used, timeout must be undefined 
	function (feedback) {
		console.log("Feedback: ", feedback);
	},
	function () {
		console.log("Timed out!");
		// In that case, you can, as an example, cancel the group
	},
	function (result) {
		console.log("Result: ", result);
	})

Group of actions structure

DataTypeDescription
labelstringGive it a name
overwriteboolWether this group will override the previously sent ones or just stack
actionsaction[]List of the actions to perform 

Action structure

DataTypeDescription
labelstringLabel of the action (see below)
orderstringOrder of the action (see below)
optional_successboolWether the action is optional or mandatory 
retry_countuint_8If the action is mandatory, the robot will retry the action this number of time 

Actions type

LabelOrderDescription
AutoNavStop point labelSends robot to a location point
LiftUpLift up the plate
LiftDownLift down the plate
ProcedureGetOutOfRollGoes out of the roll
ProcedureSetAvailableRelease robot from duty as it was assigned when requesting a robot
ProcedureDockGo to charging station
ProcedureUndockGoes out of charging station
WaitNumber of seconds or 'Pause'Pause robot in between two actions

Feedback structure

DataTypeDescription
id_groupintGroup id
group_labelstringGroup name you provided calling the action 
instuction_position_in_the_groupint
number_of_instructions_in_the_groupint
id_actionint
label_actionstringLabel of the action you provided calling the action
order_actionstringOrder of the action you provided calling the action
resultintType of result (see below) 

Result structure

DataTypeDescription
outputintType of result

Result type

LabelValueDescription
OUTPUT_PENDING0
OUTPUT_ACTIVE1
OUTPUT_PREEMPTED2
OUTPUT_SUCCEEDED3
OUTPUT_ABORTED4
OUTPUT_REJECTED5
OUTPUT_PREEMPTING6
OUTPUT_RECALLING7
OUTPUT_RECALLED8
OUTPUT_LOST9
OUTPUT_OVERWRITING10
OUTPUT_OVERWRITTEN11
OUTPUT_STALLED12
OUTPUT_BUSY13

Pause and unpause the currently processing group

This feature is a synchronous service:

client.service.call(
	'/task_manager/pause_current_group', 
	'ifollow_ll_msgs/PauseTaskManagerGroup', 
	{
		pause: true or false
	})

Cancel a group

This feature is an asynchronous service, for which you can use the Promise.then method to get the result as follow:

client.action.send(
	'/task_manager/cancel_group', 
	'ifollow_ll_msgs/CancelTaskManagerGroup', 
	{
		group_label: 'The name you chose before'
	})
1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.2.0

4 years ago

1.3.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.5

4 years ago

1.0.4

5 years ago