Summary of rosbridge use cases_ Chapter 7 running actionlib

Posted by MishieMoo on Thu, 10 Feb 2022 14:46:15 +0100

catalogue

1, What does actionlib do?

2. How to implement this operation in non ros system?

3, Write front-end code and detailed comments in HTML

4, Some understanding of actionlib on the server side

1, What does actionlib do?

Actionlib is a very important library for ROS. For example, when performing various movements, such as controlling the arm to grab a cup, the process may be complex and long. During the execution process, it may also be forced to interrupt or feed back information. Actionlib is very suitable for motion control communication like this.

In any large ROS based system, there will be such a situation that it sends a request to a node to execute a task and returns the corresponding execution result. This is usually completed by ROS services. However, in some cases, the service takes a long time to execute. If you want to get the progress of task processing during execution, or you may cancel the execution of tasks, Actionlib can realize such a function. It is a very important library of ROS. It can realize some simple state machine functions, which is a weakened version of SMACH.

2, How to implement this operation in non ros system?

2.1. Here, we use rosbridge to realize the communication between ros system and non ros system. First, we install it in the ros system

actionlib_tutorials, the learning library, installation command:

sudo apt-get install ros-noetic-actionlib-tutorials

Then install # rosbridge

sudo apt-get install ros-noetic-rosbridge-server

2.2. Then, run the following command on the server terminal:

rosrun actionlib_tutorials fibonacci_serverls

3, Write front-end code and detailed comments in HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script src="../build/roslib.js"></script>

<script>
  // Connecting to ROS
  // -----------------
  var ros = new ROSLIB.Ros({
    url : 'ws://192.168.0.123:9090'
  });

  // If there is an error on the backend, an 'error' emit will be emitted.
  ros.on('error', function(error) {
    document.getElementById('connecting').style.display = 'none';
    document.getElementById('connected. . . ').style.display = 'none';
    document.getElementById('closed').style.display = 'none';
    document.getElementById('error').style.display = 'inline';
    console.log(error);
  });

  // Find out exactly when we made a connection.
  ros.on('connection', function() {
    console.log('Connection made!');
    document.getElementById('connecting').style.display = 'none';
    document.getElementById('error').style.display = 'none';
    document.getElementById('closed').style.display = 'none';
    document.getElementById('connected').style.display = 'inline';
  });

  ros.on('close', function() {
    console.log('Connection closed.');
    document.getElementById('connecting').style.display = 'none';
    document.getElementById('connected').style.display = 'none';
    document.getElementById('closed').style.display = 'inline';
  });

  // The ActionClient
  // ----------------

  var fibonacciClient = new ROSLIB.ActionClient({
    ros : ros,
    serverName : '/fibonacci',
    actionName : 'actionlib_tutorials/FibonacciAction'
  });

  // Create a goal.
  var goal = new ROSLIB.Goal({
    actionClient : fibonacciClient,
    goalMessage : {
      order : 7
    }
  });

  // Print out their output into the terminal.
  goal.on('feedback', function(feedback) {
    console.log('Feedback: ' + feedback.sequence);
  });
  goal.on('result', function(result) {
    console.log('Final Result: ' + result.sequence);
  });

  // Send the goal to the action server.
  goal.send();
</script>
</head>

<body>
  <h1>Fibonacci ActionClient Example</h1>
  <p>Run the following commands in the terminal then refresh this page. Check the JavaScript
    console for the output.</p>
  <ol>
    <li><tt>roscore</tt></li>
    <li><tt>rosrun actionlib_tutorials fibonacci_server</tt></li>
    <li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li>
  </ol>
  <div id="statusIndicator">
    <p id="connecting">
      Connecting to rosbridge...
    </p>
    <p id="connected" style="color:#00D600; display:none">
      Connected
    </p>
    <p id="error" style="color:#FF0000; display:none">
      Error in the backend!
    </p>
    <p id="closed" style="display:none">
      Connection closed.
    </p>
  </div>
</body>
</html>

4, Some understanding of actionlib on the server side

feedback: the server regularly informs the Client of the current situation during the execution of Goal. In the case of Move Base, it represents the current posture of the robot, which means to tell the Client my current progress

goal: represents a task sent by ActionClient to ActionServer. For example, in MoveBase, its type is PoseStamped, which contains the information of the robot's moving target position.

Result: a result sent by the server ActionServer to the client ActionClient after the sending target is completed. This is different from feedback because it is sent only once.

After two lines of code are run on the terminal, run the following code again:

rostopic list

rostopic info /fibonacci/goal

From the figure below, we can see that after our server is started, the following topics will be released:

As can be seen from the following figure, our Type is consistent with HTML:

 

rosmsg show actionlib_tutorials/FibonacciAction