117 lines
2.4 KiB
HTML
117 lines
2.4 KiB
HTML
|
|
<!DOCTYPE html>
|
|||
|
|
<html>
|
|||
|
|
<head>
|
|||
|
|
<meta charset="utf-8" />
|
|||
|
|
<script type="text/javascript" src="http://static.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
|
|||
|
|
<script type="text/javascript" src="http://static.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
|
|||
|
|
<script type="text/javascript" type="text/javascript">
|
|||
|
|
|
|||
|
|
var ros = new ROSLIB.Ros({
|
|||
|
|
url : 'ws://localhost:9090'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
ros.on('connection', function() {
|
|||
|
|
console.log('Connected to websocket server.');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
ros.on('error', function(error) {
|
|||
|
|
console.log('Error connecting to websocket server: ', error);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
ros.on('close', function() {
|
|||
|
|
console.log('Connection to websocket server closed.');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
function listener(){
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
var can_pub=new ROSLIB.Topic({
|
|||
|
|
ros : ros,
|
|||
|
|
name : '/js_can',
|
|||
|
|
messageType : 'lu_ps20l_msgs/Msg_CANFrame'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var can_msg= new ROSLIB.Message({
|
|||
|
|
header: {
|
|||
|
|
stamp: {
|
|||
|
|
secs: 0,
|
|||
|
|
nsecs: 0
|
|||
|
|
},
|
|||
|
|
frame_id: "",
|
|||
|
|
seq: 0
|
|||
|
|
},
|
|||
|
|
id:0x123,
|
|||
|
|
is_rtr:false,
|
|||
|
|
is_extended:false,
|
|||
|
|
is_error:false,
|
|||
|
|
dlc:8,
|
|||
|
|
data:[1, 2, 3, 4, 5, 6, 7, 8]
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
can_pub.publish(can_msg);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
var listener = new ROSLIB.Topic({
|
|||
|
|
ros : ros,
|
|||
|
|
name : '/chatter',
|
|||
|
|
messageType : 'std_msgs/String'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
listener.subscribe(function(message) {
|
|||
|
|
console.log('Received message on ' + listener.name + ': ' + message.data);
|
|||
|
|
listener.unsubscribe();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var can_sub = new ROSLIB.Topic({
|
|||
|
|
ros : ros,
|
|||
|
|
name : '/Topic_HMI_CAN_SendFrame',//'js_can',
|
|||
|
|
messageType : 'lu_ps20l_msgs/Msg_CANFrame'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
can_sub.subscribe(function(message){
|
|||
|
|
|
|||
|
|
var p = atob(message.data);
|
|||
|
|
|
|||
|
|
|
|||
|
|
var str= 'Received can message on ' + can_sub.name + ':\n 0x' + message.id.toString(16) +'\n'+message.is_rtr +'\n'+message.is_extended +'\n'+message.is_error+'\n'+message.dlc+'\n'
|
|||
|
|
|
|||
|
|
+'0x'+p.charCodeAt(0).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(1).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(2).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(3).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(4).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(5).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(6).toString(16)+' '
|
|||
|
|
+'0x'+p.charCodeAt(7).toString(16)+'\n';
|
|||
|
|
|
|||
|
|
console.log(str);
|
|||
|
|
|
|||
|
|
document.getElementById('test').innerText= str;
|
|||
|
|
can_sub.unsubscribe();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var t2 = window.setInterval("listener()",100);
|
|||
|
|
|
|||
|
|
|
|||
|
|
</script>
|
|||
|
|
</head>
|
|||
|
|
|
|||
|
|
<body>
|
|||
|
|
<h1>Simple roslib Example 你好 欢迎使用AGV</h1>
|
|||
|
|
<p>Check your Web Console for output.</p>
|
|||
|
|
|
|||
|
|
<div id='test'> </div>
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
</body>
|
|||
|
|
</html>
|
|||
|
|
|