• ROS的roslibjs基本功能使用测试


    小结

    成功测试了roslibjs的基本功能。

    进行roslibjs的安装

    安装nodejs

    john@ubuntu:~$ sudo apt-get install nodejs
    
    john@ubuntu:~$ sudo apt-get install npm
    
    • 1
    • 2
    • 3

    安装roslibjs

    john@ubuntu:~/roslibjs$ pwd
    /home/john/roslibjs
    john@ubuntu:~/roslibjs$ 
    john@ubuntu:~$ git clone https://github.com/RobotWebTools/roslibjs.git
    john@ubuntu:~/roslibjs$ npm install
    #提示需要执行npm audit fix
    john@ubuntu:~/roslibjs$ npm audit fix
    #重新安装
    john@ubuntu:~/roslibjs$ npm install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    这里的主要测试html的代码是simple.html, 参考https://github.com/RobotWebTools/roslibjs/blob/develop/examples/simple.html

    
    
    
    "utf-8" />
    
    
    
    
    
    
    
      

    Simple roslib Example

    Run the following commands in the terminal then refresh this page. Check the JavaScript console for the output.

    1. roscore
    2. rostopic pub /listener std_msgs/String "Hello, World"
    3. rostopic echo /cmd_vel
    4. rosrun rospy_tutorials add_two_ints_server
    5. roslaunch rosbridge_server rosbridge_websocket.launch
    "statusIndicator">

    "connecting"> Connecting to rosbridge...

    "connected" style="color:#00D600; display:none"> Connected

    "error" style="color:#FF0000; display:none"> Error in the backend!

    "closed" style="display:none"> Connection closed.

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189

    进行测试

    将文件file:///home/john/roslibjs/examples/simple.html拖入到Firefox中去,打开后Firefox窗口中有如下显示:

    Simple roslib Example

    1. roscore
    2. rostopic pub /listener std_msgs/String “Hello, World”
    3. rostopic echo /cmd_vel
    4. rosrun rospy_tutorials add_two_ints_server
    5. roslaunch rosbridge_server rosbridge_websocket.launch

    Connected

    经过测试后,命令行的输出如下(开不同的窗口):
    启动roscore:

    john@ubuntu:~$ roscore
    ... logging to /home/john/.ros/log/9ce7d29e-119b-11ed-ad09-9d6885123387/roslaunch-ubuntu-14886.log
    Checking log directory for disk usage. This may take a while.
    Press Ctrl-C to interrupt
    Done checking log file disk usage. Usage is <1GB.
    
    started roslaunch server http://ubuntu:45603/
    ros_comm version 1.15.14
    
    
    SUMMARY
    ========
    
    PARAMETERS
     * /rosdistro: noetic
     * /rosversion: 1.15.14
    
    NODES
    
    auto-starting new master
    process[master]: started with pid [14895]
    ROS_MASTER_URI=http://ubuntu:11311/
    
    setting /run_id to 9ce7d29e-119b-11ed-ad09-9d6885123387
    process[rosout-1]: started with pid [14906]
    started core service [/rosout]
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    rostopic pub /listener std_msgs/String "Hello, World"输出:

    john@ubuntu:~$ rostopic pub /listener std_msgs/String "Hello, World"
    publishing and latching message. Press ctrl-C to terminate
    
    • 1
    • 2

    监测/cmd_vel的输出,接收simple.html的输入:

    john@ubuntu:~$ rostopic echo /cmd_vel
    WARNING: topic [/cmd_vel] does not appear to be published yet
    linear: 
      x: 0.1
      y: 0.2
      z: 0.3
    angular: 
      x: -0.1
      y: -0.2
      z: -0.3
    ---
    
    `roslaunch rosbridge_server rosbridge_websocket.launch`的输出:
    ```shell
    john@ubuntu:~$ roslaunch rosbridge_server rosbridge_websocket.launch
    ... logging to /home/john/.ros/log/9ce7d29e-119b-11ed-ad09-9d6885123387/roslaunch-ubuntu-15411.log
    Checking log directory for disk usage. This may take a while.
    Press Ctrl-C to interrupt
    Done checking log file disk usage. Usage is <1GB.
    
    started roslaunch server http://ubuntu:43691/
    
    SUMMARY
    ========
    
    PARAMETERS
     * /rosapi/params_glob: [*]
     * /rosapi/services_glob: [*]
     * /rosapi/topics_glob: [*]
     * /rosbridge_websocket/address: 0.0.0.0
     * /rosbridge_websocket/authenticate: False
     * /rosbridge_websocket/bson_only_mode: False
     * /rosbridge_websocket/delay_between_messages: 0
     * /rosbridge_websocket/fragment_timeout: 600
     * /rosbridge_websocket/max_message_size: None
     * /rosbridge_websocket/params_glob: [*]
     * /rosbridge_websocket/port: 9090
     * /rosbridge_websocket/retry_startup_delay: 5
     * /rosbridge_websocket/services_glob: [*]
     * /rosbridge_websocket/topics_glob: [*]
     * /rosbridge_websocket/unregister_timeout: 10
     * /rosbridge_websocket/use_compression: False
     * /rosbridge_websocket/websocket_external_port: None
     * /rosbridge_websocket/websocket_ping_interval: 0
     * /rosbridge_websocket/websocket_ping_timeout: 30
     * /rosdistro: noetic
     * /rosversion: 1.15.14
    
    NODES
      /
        rosapi (rosapi/rosapi_node)
        rosbridge_websocket (rosbridge_server/rosbridge_websocket)
    
    ROS_MASTER_URI=http://localhost:11311
    
    process[rosbridge_websocket-1]: started with pid [15432]
    process[rosapi-2]: started with pid [15434]
    2022-08-01 21:13:32+0800 [-] Log opened.
    [INFO] [1659359612.771473]: Rosapi started
    2022-08-01 21:13:32+0800 [-] registered capabilities (classes):
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.call_service.CallService'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.advertise.Advertise'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.publish.Publish'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.subscribe.Subscribe'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.defragmentation.Defragment'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.advertise_service.AdvertiseService'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.service_response.ServiceResponse'>
    2022-08-01 21:13:32+0800 [-]  - <class 'rosbridge_library.capabilities.unadvertise_service.UnadvertiseService'>
    2022-08-01 21:13:33+0800 [-] WebSocketServerFactory starting on 9090
    2022-08-01 21:13:33+0800 [-] Starting factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0x7fe5550d17f0>
    2022-08-01 21:13:33+0800 [-] [INFO] [1659359613.034557]: Rosbridge WebSocket server started at ws://0.0.0.0:9090
    2022-08-01 21:43:13+0800 [-] [INFO] [1659361393.971597]: Client connected.  1 clients total.
    2022-08-01 21:43:14+0800 [-] [ERROR] [1659361394.318899]: [Client 0] [id: advertise:/tf2_web_republisher/goal:1] advertise: Unable to load the manifest for package tf2_web_republisher. Caused by: tf2_web_republisher
    2022-08-01 21:43:14+0800 [-] ROS path [0]=/opt/ros/noetic/share/ros
    2022-08-01 21:43:14+0800 [-] ROS path [1]=/home/john/jetmax/src
    2022-08-01 21:43:14+0800 [-] ROS path [2]=/home/john/catkin_ws/src
    2022-08-01 21:43:14+0800 [-] ROS path [3]=/opt/ros/noetic/share
    2022-08-01 21:43:15+0800 [-] [ERROR] [1659361395.049878]: [Client 0] [id: subscribe:/tf2_web_republisher/feedback:3] subscribe: Unable to load the manifest for package tf2_web_republisher. Caused by: tf2_web_republisher
    2022-08-01 21:43:15+0800 [-] ROS path [0]=/opt/ros/noetic/share/ros
    2022-08-01 21:43:15+0800 [-] ROS path [1]=/home/john/jetmax/src
    2022-08-01 21:43:15+0800 [-] ROS path [2]=/home/john/catkin_ws/src
    2022-08-01 21:43:15+0800 [-] ROS path [3]=/opt/ros/noetic/share
    2022-08-01 21:43:15+0800 [-] [ERROR] [1659361395.054902]: [Client 0] [id: publish:/tf2_web_republisher/goal:4] publish: Cannot infer topic type for topic /tf2_web_republisher/goal as it is not yet advertised
    2022-08-01 21:43:20+0800 [-] [INFO] [1659361400.824869]: Client disconnected. 0 clients total.
    2022-08-01 21:43:21+0800 [-] [INFO] [1659361401.006295]: Client connected.  1 clients total.
    2022-08-01 21:43:21+0800 [-] [ERROR] [1659361401.142243]: [Client 1] [id: advertise:/tf2_web_republisher/goal:1] advertise: Unable to load the manifest for package tf2_web_republisher. Caused by: tf2_web_republisher
    2022-08-01 21:43:21+0800 [-] ROS path [0]=/opt/ros/noetic/share/ros
    2022-08-01 21:43:21+0800 [-] ROS path [1]=/home/john/jetmax/src
    2022-08-01 21:43:21+0800 [-] ROS path [2]=/home/john/catkin_ws/src
    2022-08-01 21:43:21+0800 [-] ROS path [3]=/opt/ros/noetic/share
    2022-08-01 21:43:21+0800 [-] [ERROR] [1659361401.146786]: [Client 1] [id: subscribe:/tf2_web_republisher/feedback:3] subscribe: Unable to load the manifest for package tf2_web_republisher. Caused by: tf2_web_republisher
    2022-08-01 21:43:21+0800 [-] ROS path [0]=/opt/ros/noetic/share/ros
    2022-08-01 21:43:21+0800 [-] ROS path [1]=/home/john/jetmax/src
    2022-08-01 21:43:21+0800 [-] ROS path [2]=/home/john/catkin_ws/src
    2022-08-01 21:43:21+0800 [-] ROS path [3]=/opt/ros/noetic/share
    2022-08-01 21:43:21+0800 [-] [ERROR] [1659361401.154688]: [Client 1] [id: publish:/tf2_web_republisher/goal:4] publish: Cannot infer topic type for topic /tf2_web_republisher/goal as it is not yet advertised
    2022-08-01 21:45:54+0800 [-] [INFO] [1659361554.937012]: Client disconnected. 0 clients total.
    2022-08-01 21:45:55+0800 [-] [INFO] [1659361555.125830]: Client connected.  1 clients total.
    2022-08-01 21:45:55+0800 [-] [ERROR] [1659361555.218223]: [Client 2] [id: advertise:/tf2_web_republisher/goal:1] advertise: Unable to load the manifest for package tf2_web_republisher. Caused by: tf2_web_republisher
    2022-08-01 21:45:55+0800 [-] ROS path [0]=/opt/ros/noetic/share/ros
    2022-08-01 21:45:55+0800 [-] ROS path [1]=/home/john/jetmax/src
    2022-08-01 21:45:55+0800 [-] ROS path [2]=/home/john/catkin_ws/src
    2022-08-01 21:45:55+0800 [-] ROS path [3]=/opt/ros/noetic/share
    2022-08-01 21:45:55+0800 [-] [ERROR] [1659361555.223203]: [Client 2] [id: subscribe:/tf2_web_republisher/feedback:3] subscribe: Unable to load the manifest for package tf2_web_republisher. Caused by: tf2_web_republisher
    2022-08-01 21:45:55+0800 [-] ROS path [0]=/opt/ros/noetic/share/ros
    2022-08-01 21:45:55+0800 [-] ROS path [1]=/home/john/jetmax/src
    2022-08-01 21:45:55+0800 [-] ROS path [2]=/home/john/catkin_ws/src
    2022-08-01 21:45:55+0800 [-] ROS path [3]=/opt/ros/noetic/share
    2022-08-01 21:45:55+0800 [-] [ERROR] [1659361555.227773]: [Client 2] [id: publish:/tf2_web_republisher/goal:4] publish: Cannot infer topic type for topic /tf2_web_republisher/goal as it is not yet advertised
    2022-08-01 21:46:22+0800 [-] [INFO] [1659361582.056263]: Client disconnected. 0 clients total.
    2022-08-01 21:46:26+0800 [-] [INFO] [1659361586.740728]: Client connected.  1 clients total.
    2022-08-01 21:46:26+0800 [-] [INFO] [1659361586.873740]: [Client 3] Subscribed to /listener
    2022-08-01 21:46:26+0800 [-] [INFO] [1659361586.910506]: [Client 3] Advertised service /set_bool.
    2022-08-01 21:46:26+0800 [-] [INFO] [1659361586.959539]: [Client 3] Unsubscribed from /listener
    2022-08-01 21:50:56+0800 [-] [INFO] [1659361856.983826]: Client disconnected. 0 clients total.
    2022-08-01 21:50:57+0800 [-] [INFO] [1659361857.427746]: Client connected.  1 clients total.
    2022-08-01 21:50:57+0800 [-] [INFO] [1659361857.462512]: [Client 4] Subscribed to /listener
    2022-08-01 21:50:57+0800 [-] [WARN] [1659361857.465272]: [Client 4] Duplicate service advertised. Overwriting /set_bool.
    2022-08-01 21:50:57+0800 [-] [INFO] [1659361857.481433]: [Client 4] Advertised service /set_bool.
    2022-08-01 21:50:57+0800 [-] [INFO] [1659361857.527972]: [Client 4] Unsubscribed from /listener
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121

    rosrun rospy_tutorials add_two_ints_server的输出,进行了1+2=3的服务调用:

    john@ubuntu:~$ rosrun rospy_tutorials add_two_ints_server
    Returning [1 + 2 = 3]
    
    
    • 1
    • 2
    • 3

    Ctrl + Shift + K 打开Firefox的Console窗口,在Firefox的console窗口里有以下输出,与simple.html的源代码匹配,测试成功。

    Connection closed. simple.html:32:13
    Connection made! simple.html:24:13
    Result for service call on /add_two_ints: 3 simple.html:108:13
    Received message on /listener: Hello, World simple.html:82:13
    Array(27) [ "/run_id", "/roslaunch/uris/host_ubuntu__45603", "/roslaunch/uris/host_ubuntu__43691", "/rosversion", "/rosdistro", "/rosbridge_websocket/authenticate", "/rosbridge_websocket/port", "/rosbridge_websocket/address", "/rosbridge_websocket/retry_startup_delay", "/rosbridge_websocket/fragment_timeout", … ]0: "/run_id"1: "/roslaunch/uris/host_ubuntu__45603"2: "/roslaunch/uris/host_ubuntu__43691"3: "/rosversion"4: "/rosdistro"5: "/rosbridge_websocket/authenticate"6: "/rosbridge_websocket/port"7: "/rosbridge_websocket/address"8: "/rosbridge_websocket/retry_startup_delay"9: "/rosbridge_websocket/fragment_timeout"10: "/rosbridge_websocket/delay_between_messages"11: "/rosbridge_websocket/max_message_size"12: "/rosbridge_websocket/unregister_timeout"13: "/rosbridge_websocket/use_compression"14: "/rosbridge_websocket/websocket_ping_interval"15: "/rosbridge_websocket/websocket_ping_timeout"16: "/rosbridge_websocket/websocket_external_port"17: "/rosbridge_websocket/topics_glob"18: "/rosbridge_websocket/services_glob"19: "/rosbridge_websocket/params_glob"20: "/rosbridge_websocket/bson_only_mode"21: "/rosbridge_websocket/actual_port"22: "/rosapi/topics_glob"23: "/rosapi/services_glob"24: "/rosapi/params_glob"25: "/favorite_color"26: "/max_vel_y"
    ​
    length: 27<prototype>: Array []
    simple.html:133:13
    MAX VAL: 0.8 simple.html:145:13
    My robot's favorite color is red simple.html:158:13
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67

    参考

    解决在Ubuntu安装nodejs,roslibjs时出现的问题
    关于js和ros进行交互roslibjs
    Basic ROS functionality with roslibjs
    https://github.com/RobotWebTools/roslibjs/blob/develop/examples/simple.html
    SIMPLE TUTORIAL ON ROSBRIDGE AND ROSLIBJS
    ROS与javascript入门教程-roslibjs-基本功能

  • 相关阅读:
    记录字节跳动前端面试,四轮技术面
    【汇编】“转移”综述、操作符offset、jmp指令
    element-ui中Form表单使用自定义验证规则
    元组高级用法
    电容 stm32
    一文深入底层分析Redis对象结构
    拉格朗日粒子扩散FLEXPART模式
    Rockchip PX30/RK3326 Android开机时间优化
    linux 中断子系统
    zookeeper教程
  • 原文地址:https://blog.csdn.net/scruffybear/article/details/126112107