Files
apt-nl-map/static/Magic4/BAK/test_ros_5.html
2024-12-04 10:21:04 +08:00

130 lines
2.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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 talker1(str){
alert("talker1函数:"+str);
}
function talker2(id){
element = document.getElementById(id);
alert("talker2函数:"+element.value);
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);
}
function listener(){
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>
<form name=f1>
<input type=text name=t1></input>
<input type=button value=ok onclick=talker1(t1.value)></input>
</form>
<input type=text id="id1" />
<input type=button value=ok onclick=talker2("id1") />
</body>
</html>