Roslibjs for a client to communicate with simple action Server
Hello, I made a simple action server and client guided by the tutorials, I was able to make everything work. I wanted to take one step more and try to make the action client using roslibjs
, then this Error came up:
[INFO] [WallTime: 1424105276.754999] Client connected. 1 clients total.
[ERROR] [WallTime: 1424105276.766179] [Client 0] [id: advertise:/control/goal:1] advertise: gamma/src/control/ControlActionGoal is not a valid type string
[INFO] [WallTime: 1424105276.921603] [Client 0] Subscribed to /control/status
[ERROR] [WallTime: 1424105276.925383] [Client 0] [id: subscribe:/control/feedback:4] subscribe: gamma/src/control/ControlActionFeedback is not a valid type string
[ERROR] [WallTime: 1424105276.930062] [Client 0] [id: subscribe:/control/result:5] subscribe: gamma/src/control/ControlActionResult is not a valid type string
I think that this Error is associated to the actionName
field when ROSLIB.ActionClient
is called.
The route to the .action file is: ~/Desktop/gamma/src/control/Control.action
The html file with the client is here:
<!DOCTYPE html>
<html>
<head>
<title> Control client </title>
<meta charset="utf-8"/>
<script type="text/javascript" src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
<script type="text/javascript" type="text/javascript">
//connect to ROS
var ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' });
//emit the error on the backend if exist
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';
});
///////////////////////////////////////////////////////////////////
//Action Client
///////////////////////////////////////////////////////////////////
// Conect to the server on charge of the mobile control of the turtlebot
var controlClient = new ROSLIB.ActionClient({
ros : ros,
serverName: '/control',
actionName: 'gamma/src/control/ControlAction'
});
//Created function to move foward the turtlebot
function pubMessage() {
//Create the variable that will be associated to the goal
var twist = new ROSLIB.Message ({
linear : {
x : 0.1,
y : 0.0,
z : 0.0
},
angular : {
x : 0.0,
y : 0.0,
z : 0.0
}
});
//Create the goal
var goal = new ROSLIB.Goal({
actionClient : controlClient,
goalMessage : twist
});
//Send the goal to the server to execute the callbacks
goal.send();
console.log("Goal sent forward");
return true;
}
</script>
</head>
<body>
<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>
<div> <button id="forward" type="action" onclick="pubMessage()">Forward</button> </div>
</body>
</html>
The error is reported in the rosbridge
terminal ...
Is your action server set up correctly? That is, are you able to call the action natively in ROS?
yes, the action server is working and I am able to call the action natively in ROS (I did it changing the Tutorials)
Is there a specific folder that the HTML file needs to be saved ? Don't get me wrong, I am not very familiar with ROS. Usually I use a web server , which there is a folder to place it. When I am running the server so I will be able to call the HTML via localhost as an example.
The HTML can be hosted anywhere, it is independent of the ROS system. The client will make a connection to ROS via rosbridge over websockets.