代码解析:
代码段:
var imageTopic = new ROSLIB.Topic({
ros : ros,
name : '/camera/image/compressed',
messageType : 'sensor_msgs/CompressedImage'
});
var imuTopic = new ROSLIB.Topic({
ros : ros,
name : '/gyro',
messageType : 'sensor_msgs/Imu'
解释:
创建图片话题对象和imu话题对象
代码段:
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
var data = canvas.toDataURL('image/jpeg');
var imageMessage = new ROSLIB.Message({
format : "jpeg",
data : data.replace("data:image/jpeg;base64,", "")
解释:
获取图片并转化成加密的字符串
代码段:
var imuMessage = new ROSLIB.Message({
header : {
frame_id : "world"
},
解释:
构造imu的消息
代码段:
startstopicon.addEventListener('click', function(ev){
if(cameraTimer == null) {
ros.connect("ws://" + window.location.hostname + ":9090");
cameraOn();
cameraTimer = setInterval(function(){
takepicture();
}, 250);
// publish an image 4 times per second
imuTimer = setInterval(function(){
imusnapshot();
}, 100);
// publish an IMU message 10 times per second
解释:
设置发布频率
运行:
服务器,新终端,运行
roslaunch rosbridge_server rosbridge_websocket.launch
安卓手机端,chrome浏览器,访问:
服务器,新终端,运行rviz
rosrun rviz rviz
订阅imu和image话题,显示相应的内容
参考:
%20video%20and%20IMU%20data%20with%20roslibjs
纠错,疑问,交流:
请进入讨论区或
点击加入Q群
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号
标签:
上一篇:
下一篇:
分类导航