moved files around to make it more user friendly
This commit is contained in:
100
ProjectFiles/js/ros_scripts.js
Normal file
100
ProjectFiles/js/ros_scripts.js
Normal file
@@ -0,0 +1,100 @@
|
||||
var ros = new ROSLIB.Ros();
|
||||
|
||||
ros.connectioninfo = ['ws://', '192', '168', '0', '100', '9090'];
|
||||
// ros.connectionName = 'ws://localhost:9090';
|
||||
ros.connectionName = 'ws://192.168.0.100:9090';
|
||||
// If there is an error on the backend, an 'error' emit will be emitted.
|
||||
ros.on('error', function(error) {
|
||||
document.getElementById("ConnectionIPForm").className = "form-group has-warning has-feedback";
|
||||
document.getElementById("ConnectionIPInput").value = ros.connectionName;
|
||||
document.getElementById("ConnectionIPLabel").innerHTML = 'No connection';
|
||||
document.getElementById("ConnectionButton").className = "btn btn-warning"
|
||||
document.getElementById("rosbridgeconnection_badge").innerHTML = 'No connection';
|
||||
|
||||
rosbridgeconnection_badge
|
||||
console.log(error);192
|
||||
});
|
||||
// Find out exactly when we made a connection.
|
||||
ros.on('connection', function() {
|
||||
console.log('Connection made!');
|
||||
document.getElementById("ConnectionIPForm").className = "form-group has-success has-feedback";
|
||||
document.getElementById("ConnectionIPInput").value = ros.connectionName;
|
||||
document.getElementById("ConnectionIPLabel").innerHTML = 'Connection made at:';
|
||||
document.getElementById("rosbridgeconnection_badge").innerHTML = 'Connected';
|
||||
document.getElementById("ConnectionButton").className = "btn btn-success"
|
||||
|
||||
|
||||
});
|
||||
|
||||
ros.on('close', function() {
|
||||
console.log('Connection closed.');
|
||||
});
|
||||
// Create a connection to the rosbridge WebSocket server.
|
||||
ros.connect(ros.connectionName);
|
||||
|
||||
|
||||
// attept to connect to the ros master from the IP given orgrab it from the form
|
||||
ros.attemptConnection = function(ipAddress)
|
||||
{
|
||||
if( typeof ipAddress !== "undefined")
|
||||
{
|
||||
ros.connectionName = ipAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
ros.connectionName = document.getElementById("ConnectionIPInput").value
|
||||
}
|
||||
console.log('Connection = ' + ros.connectionName);
|
||||
ros.connect(ros.connectionName);
|
||||
}
|
||||
|
||||
|
||||
function getTopics() {
|
||||
|
||||
var topicsClient = new ROSLIB.Service({
|
||||
ros : ros,
|
||||
name : '/rosapi/topics',
|
||||
serviceType : '/rosapi/Topics'
|
||||
});
|
||||
|
||||
var request = new ROSLIB.ServiceRequest();
|
||||
|
||||
topicsClient.callService(request, function(result) {
|
||||
ros.topics = result.topics;
|
||||
});
|
||||
|
||||
return ros.topics
|
||||
};
|
||||
|
||||
function getNodes() {
|
||||
|
||||
var topicsClient = new ROSLIB.Service({
|
||||
ros : ros,
|
||||
name : '/rosapi/nodes',
|
||||
serviceType : '/rosapi/nodes'
|
||||
});
|
||||
|
||||
var request = new ROSLIB.ServiceRequest();
|
||||
|
||||
topicsClient.callService(request, function(result) {
|
||||
ros.nodes = result.nodes;
|
||||
});
|
||||
|
||||
return ros.nodes
|
||||
};
|
||||
|
||||
function getTime() {
|
||||
|
||||
var topicsClient = new ROSLIB.Service({
|
||||
ros : ros,
|
||||
name : '/rosapi/get_time',
|
||||
serviceType : '/rosapi/GetTime'
|
||||
});
|
||||
|
||||
var request = new ROSLIB.ServiceRequest({});
|
||||
|
||||
topicsClient.callService(request, function(result) {
|
||||
console.log("Getting Time...");
|
||||
console.log(result.time.secs);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user