0x00 源码简介

关注过ROS小课堂公众号或者优酷视频教程的应该对ROS小课堂的三轮全向移动小车有所了解,我已经制作了大概10集关于三轮全向移动小车的教程,由于一直跟大家说要开放源码,这次终于等到ROS小课堂的服务器搭建的差不多了才把源码上传至服务器来开源。源码中包含了安卓助手端app的全部源码,arduino控制源码,主控板运行的ROS源码,SLAM导航源码,使用的是RPLidar A2,视频监控等,目前该源码经过在树莓派3B上ROS indigo版本下经过编译测试,可以正常运行,所有源码已上传至ROS小课堂的gerrit系统中,开放给大家进行下载,目前服务器端正在搭建禅道软件项目管理系统,搭建完成后,大家就可以在禅道上来进行提bug和更多需求,到时候我会根据bug和需求的描述来继续维护代码,当然也非常欢迎大家参与到项目中来,共同来维护代码,贡献自己的一份力量,下面来几张三轮全向移动机器人的图片供大家参考:


0x01 源码下载

源码下载方式分为两种:一种是匿名用户,可以随便下载代码,但是没有提交代码的权限;另外一种是gerrit系统的注册用户,下载代码后还可以提交修改代码,下面分别介绍两种下载方式:

(1)匿名用户下载

(2)gerrit注册用户下载

对于gerrit注册用户,需要首先在浏览器中输入www.corvin.cn:8080/gerrit/回车后会弹出登录框提示进行帐号秘密登录,如下图所示:

在登录系统后,然后就可以选择三轮全向移动小车的代码库corvinRobot_YOYO,具体操作如下图所示:

在复制了下载命令后就可以直接在终端中开始下载代码了,具体的下载流程如下所示:


0x02 ROS源码简析

对于源码的解析,首先我们来看ROS相关的代码:

接下来看整个源码的编译过程,首先是第一次编译会出错,如下所示(编译过程日志太长,所以略有删减):

corvin@workspace:~/corvinRobot_YOYO/ROSCode$ catkin_make
Base path: /home/corvin/corvinRobot_YOYO/ROSCode
Source space: /home/corvin/corvinRobot_YOYO/ROSCode/src
Build space: /home/corvin/corvinRobot_YOYO/ROSCode/build
Devel space: /home/corvin/corvinRobot_YOYO/ROSCode/devel
Install space: /home/corvin/corvinRobot_YOYO/ROSCode/install
####
#### Running command: "cmake /home/corvin/corvinRobot_YOYO/ROSCode/src -DCATKIN_DEVEL_PREFIX=/home/corvin/corvinRobot_YOYO/ROSCode/devel -DCMAKE_INSTALL_PREFIX=/home/corvin/corvinRobot_YOYO/ROSCode/install -G Unix Makefiles" in "/home/corvin/corvinRobot_YOYO/ROSCode/build"
####
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using CATKIN_DEVEL_PREFIX: /home/corvin/corvinRobot_YOYO/ROSCode/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/indigo
-- This workspace overlays: /opt/ros/indigo
-- Found PythonInterp: /usr/bin/python (found version "2.7.6") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/corvin/corvinRobot_YOYO/ROSCode/build/test_results
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 29 packages in topological order:
-- ~~  - head_arduino_bridge (metapackage)
-- ~~  - head_arduino_firmware
-- ~~  - head_arduino_python
-- ~~  - rbx1 (metapackage)
-- ~~  - ros_arduino_bridge (metapackage)
-- ~~  - ros_arduino_firmware
-- ~~  - ros_arduino_python
-- ~~  - head_arduino_msgs
-- ~~  - ros_arduino_msgs
-- ~~  - teleop_twist_keyboard
-- ~~  - android_app_communication
-- ~~  - bringup
-- ~~  - check_sensor_status
-- ~~  - description
-- ~~  - navigation
-- ~~  - projector_control
-- ~~  - protect_motors
-- ~~  - rbx1_bringup
-- ~~  - rbx1_speech
-- ~~  - camera_monitor
-- ~~  - rbx1_vision
-- ~~  - rplidar_ros
-- ~~  - razor_imu_9dof
-- ~~  - rbx1_dynamixels
-- ~~  - rbx1_apps
-- ~~  - rbx1_nav
-- ~~  - rbx1_description
-- ~~  - usb_cam
-- ~~  - voice_system
Scanning dependencies of target usb_cam
[ 11%] Building CXX object usb_cam/CMakeFiles/usb_cam.dir/src/usb_cam.cpp.o
[ 12%] Building CXX object rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/arch/linux/timer.cpp.o
Scanning dependencies of target xf_tts_node
[ 13%] Building CXX object voice_system/CMakeFiles/xf_tts_node.dir/src/xf_tts.cpp.o
/home/corvin/corvinRobot_YOYO/ROSCode/src/protect_motors/src/protect_motors.cpp:3:42: fatal error: ros_arduino_msgs/AnalogFloat.h: No such file or directory
 #include "ros_arduino_msgs/AnalogFloat.h"
                                          ^
compilation terminated.
/home/corvin/corvinRobot_YOYO/ROSCode/src/projector_control/src/projector_control.cpp:11:53: fatal error: android_app_communication/androidLogMsg.h: No such file or directory
 #include "android_app_communication/androidLogMsg.h"
                                                     ^
compilation terminated.
/home/corvin/corvinRobot_YOYO/ROSCode/src/check_sensor_status/src/main.cpp:5:38: fatal error: head_arduino_msgs/Analog.h: No such file or directory
 #include "head_arduino_msgs/Analog.h"
                                      ^
compilation terminated.
[ 14%] Building CXX object rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/hal/thread.cpp.o
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/rplidar_ros/rplidarNodeClient
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/voice_system/xf_tts_node
Linking CXX shared library /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/libusb_cam.so
[ 15%] Building CXX object rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/rplidar_driver.cpp.o
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/camera_monitor/camera_monitor_node
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/rplidar_ros/rplidarNode
[ 15%] Built target usb_cam
Scanning dependencies of target head_arduino_msgs_generate_messages_py
[ 16%] Generating Python from MSG head_arduino_msgs/ArduinoConstants
[ 17%] Generating Python from MSG head_arduino_msgs/Analog
[ 18%] Generating Python from MSG head_arduino_msgs/SensorState
[ 19%] Generating Python from MSG head_arduino_msgs/AnalogFloat
[ 19%] Built target rplidarNodeClient
[ 19%] [ 21%] [ 21%] Built target xf_tts_node
[ 21%] Built target rplidarNode
Generating Python from MSG head_arduino_msgs/Digital
[ 88%] Built target camera_monitor_node
[ 89%] Generating C++ code from ros_arduino_msgs/AnalogRead.srv
[ 89%] Generating C++ code from ros_arduino_msgs/AlarmWrite.srv
[ 90%] Generating C++ code from ros_arduino_msgs/AnalogWrite.srv
[ 91%] Generating C++ code from ros_arduino_msgs/ServoWrite.srv
[ 92%] Generating C++ code from ros_arduino_msgs/LightShow.srv
[ 93%] Generating C++ code from ros_arduino_msgs/DigitalSetDirection.srv
[ 93%] Built target head_arduino_msgs_generate_messages_cpp
[ 94%] Generating C++ code from ros_arduino_msgs/DigitalRead.srv
[ 95%] Generating C++ code from ros_arduino_msgs/ServoRead.srv
[ 95%] Built target ros_arduino_msgs_generate_messages_cpp
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

第一次编译出错是因为找不到自定义的头文件,不过不要紧,只要我们source devel/setup.bash就可以了,具体操作如下图所示:

corvin@workspace:~/corvinRobot_YOYO/ROSCode$ ls
build  devel  src
corvin@workspace:~/corvinRobot_YOYO/ROSCode$ source devel/setup.bash
corvin@workspace:~/corvinRobot_YOYO/ROSCode$ catkin_make
Base path: /home/corvin/corvinRobot_YOYO/ROSCode
Source space: /home/corvin/corvinRobot_YOYO/ROSCode/src
Build space: /home/corvin/corvinRobot_YOYO/ROSCode/build
Devel space: /home/corvin/corvinRobot_YOYO/ROSCode/devel
Install space: /home/corvin/corvinRobot_YOYO/ROSCode/install
####
#### Running command: "make cmake_check_build_system" in "/home/corvin/corvinRobot_YOYO/ROSCode/build"
####
####
#### Running command: "make -j8 -l8" in "/home/corvin/corvinRobot_YOYO/ROSCode/build"
####
[  0%] Built target std_msgs_generate_messages_py
[  0%] Built target _head_arduino_msgs_generate_messages_check_deps_ServoWrite
[  0%] [  0%] [  0%] [  0%] [  0%] Built target _head_arduino_msgs_generate_messages_check_deps_Analog
Built target _head_arduino_msgs_generate_messages_check_deps_AnalogRead
Built target _head_arduino_msgs_generate_messages_check_deps_AnalogWrite
Built target _head_arduino_msgs_generate_messages_check_deps_DigitalWrite
Built target _head_arduino_msgs_generate_messages_check_deps_AnalogFloat
[  0%] Built target _head_arduino_msgs_generate_messages_check_deps_Digital
[  0%] [  0%] Built target std_msgs_generate_messages_lisp
Built target std_msgs_generate_messages_cpp
[  0%] [  0%] Built target _head_arduino_msgs_generate_messages_check_deps_IIC
Built target _head_arduino_msgs_generate_messages_check_deps_ArduinoConstants
[  0%] Built target _head_arduino_msgs_generate_messages_check_deps_DigitalRead
[  0%] Built target _head_arduino_msgs_generate_messages_check_deps_DigitalSetDirection
[  0%] [  0%] Built target _head_arduino_msgs_generate_messages_check_deps_SensorState
Built target _head_arduino_msgs_generate_messages_check_deps_ServoRead
[  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_AnalogFloat
[  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_ServoWrite
[  0%] [  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_AnalogRead
Built target _ros_arduino_msgs_generate_messages_check_deps_SensorState
[  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_DigitalWrite
[  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_AnalogWrite
[  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_Analog
[  0%] [  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_DigitalRead
Built target _ros_arduino_msgs_generate_messages_check_deps_LightShow
[  0%] Built target _ros_arduino_msgs_generate_messages_check_deps_ArduinoConstants
[  1%] [  2%] [  3%] Building CXX object protect_motors/CMakeFiles/protect_motors_node.dir/src/protect_motors.cpp.o
Building CXX object projector_control/CMakeFiles/projector_control_node.dir/src/projector_control.cpp.o
Building CXX object check_sensor_status/CMakeFiles/check_sensor_status_node.dir/src/main.cpp.o
[  3%] [  3%] [  3%] Built target _ros_arduino_msgs_generate_messages_check_deps_ServoRead
Built target _ros_arduino_msgs_generate_messages_check_deps_Digital
Built target _ros_arduino_msgs_generate_messages_check_deps_AlarmWrite
[  3%] [  3%] Built target _ros_arduino_msgs_generate_messages_check_deps_DigitalSetDirection
Built target _android_app_communication_generate_messages_check_deps_androidLogMsg
[  4%] [  5%] [  7%] Built target rplidarNodeClient
Built target camera_monitor_node
Built target rbx1_nav_gencfg
[  8%] Built target razor_imu_9dof_gencfg
[ 13%] Built target rplidarNode
[ 27%] [ 39%] Built target head_arduino_msgs_generate_messages_py
Built target head_arduino_msgs_generate_messages_lisp
[ 41%] [ 41%] Built target usb_cam
Built target xf_tts_node
[ 54%] Built target head_arduino_msgs_generate_messages_cpp
Scanning dependencies of target android_app_communication_generate_messages_py
[ 79%] [ 82%] Scanning dependencies of target android_app_communication_generate_messages_lisp
Built target ros_arduino_msgs_generate_messages_lisp
Built target ros_arduino_msgs_generate_messages_py
[ 83%] [ 84%] Scanning dependencies of target android_app_communication_generate_messages_cpp
Scanning dependencies of target usb_cam_node
Generating Lisp code from android_app_communication/androidLogMsg.msg
Generating Python from MSG android_app_communication/androidLogMsg
[ 97%] [ 97%] Built target ros_arduino_msgs_generate_messages_cpp
Generating C++ code from android_app_communication/androidLogMsg.msg
Scanning dependencies of target head_arduino_msgs_generate_messages
[ 97%] Built target head_arduino_msgs_generate_messages
Scanning dependencies of target ros_arduino_msgs_generate_messages
[ 97%] Built target ros_arduino_msgs_generate_messages
[ 97%] Built target android_app_communication_generate_messages_lisp
[ 98%] [100%] Generating Python msg __init__.py for android_app_communication
Building CXX object usb_cam/CMakeFiles/usb_cam_node.dir/nodes/usb_cam_node.cpp.o
[100%] Built target android_app_communication_generate_messages_py
[100%] Built target android_app_communication_generate_messages_cpp
Scanning dependencies of target android_app_communication_generate_messages
[100%] Built target android_app_communication_generate_messages
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/projector_control/projector_control_node
[100%] Built target projector_control_node
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/protect_motors/protect_motors_node
[100%] Built target protect_motors_node
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/check_sensor_status/check_sensor_status_node
[100%] Built target check_sensor_status_node
Linking CXX executable /home/corvin/corvinRobot_YOYO/ROSCode/devel/lib/usb_cam/usb_cam_node
[100%] Built target usb_cam_node

0x03 rosjava源码简析

rosjava是使用java语言实现的一个ROS代码框架,基本上可以与ROS系统无缝衔接通信,你在ubuntu安装的ROS系统中用到的功能在rosjava中都可以实现,rosjava就是这个java版本的ros的源码,我们可以在该源码基础上开发出属于自己定义的各类通信topic消息格式,可以将其编译成jar包这样就可以直接在我们的安卓app中直接引用,这样我们的安卓app就可以直接和ROS系统通信了。关于rosjava的更详细介绍也可以去ROS Wiki的官网查看:http://wiki.ros.org/rosjava/

由于整个编译过程较长,可以直接看下面的编译过程(编译过程日志太长,所以略有删减):

corvin@workspace:~/corvinRobot_YOYO/rosjava$ catkin_make
Base path: /home/corvin/corvinRobot_YOYO/rosjava
Source space: /home/corvin/corvinRobot_YOYO/rosjava/src
Build space: /home/corvin/corvinRobot_YOYO/rosjava/build
Devel space: /home/corvin/corvinRobot_YOYO/rosjava/devel
Install space: /home/corvin/corvinRobot_YOYO/rosjava/install
####
#### Running command: "cmake /home/corvin/corvinRobot_YOYO/rosjava/src -DCATKIN_DEVEL_PREFIX=/home/corvin/corvinRobot_YOYO/rosjava/devel -DCMAKE_INSTALL_PREFIX=/home/corvin/corvinRobot_YOYO/rosjava/install -G Unix Makefiles" in "/home/corvin/corvinRobot_YOYO/rosjava/build"
####
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using CATKIN_DEVEL_PREFIX: /home/corvin/corvinRobot_YOYO/rosjava/devel
-- Using CMAKE_PREFIX_PATH: /home/corvin/corvinRobot_YOYO/ROSCode/devel;/opt/ros/indigo
-- This workspace overlays: /home/corvin/corvinRobot_YOYO/ROSCode/devel;/opt/ros/indigo
-- Found PythonInterp: /usr/bin/python (found version "2.7.6") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/corvin/corvinRobot_YOYO/rosjava/build/test_results
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 13 packages in topological order:
-- ~~  - rosjava_build_tools
-- ~~  - rosjava_bootstrap
-- ~~  - genjava
-- ~~  - rosjava (metapackage)
-- ~~  - head_arduino_msgs
-- ~~  - ros_arduino_msgs
-- ~~  - rosgraph_msgs
-- ~~  - rosjava_test_msgs
-- ~~  - rosjava_extras
-- ~~  - std_srvs
-- ~~  - android_app_communication
-- ~~  - rocon_rosjava_core
-- ~~  - zeroconf_jmdns_suite
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Uploaded 6K
[ 98%] Built target gradle-zeroconf_jmdns_suite
Scanning dependencies of target head_arduino_msgs_generate_messages
[ 98%] Built target head_arduino_msgs_generate_messages
Scanning dependencies of target ros_arduino_msgs_generate_messages
[ 98%] Built target ros_arduino_msgs_generate_messages
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
Uploading: com/github/robotics_in_concert/rocon_rosjava_core/master_info/0.2.0/master_info-0.2.0.jar to repository remote at file:/home/corvin/corvinRobot_YOYO/rosjava/devel/share/maven/
Transferring 4K from remote
Uploaded 4K
Uploading: com/github/robotics_in_concert/rocon_rosjava_core/rocon_interactions/0.2.0/rocon_interactions-0.2.0.jar to repository remote at file:/home/corvin/corvinRobot_YOYO/rosjava/devel/share/maven/
Transferring 6K from remote
Uploaded 6K
Uploading: com/github/robotics_in_concert/rocon_rosjava_core/rosjava_utils/0.2.0/rosjava_utils-0.2.0.jar to repository remote at file:/home/corvin/corvinRobot_YOYO/rosjava/devel/share/maven/
Transferring 11K from remote
Uploaded 11K
[ 98%] Built target gradle-rocon_rosjava_core

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':runtime'.
> Could not resolve org.ros.rosjava_messages:roscpp:1.11.21.
  Required by:
      org.ros.rosjava_messages:android_app_communication:0.0.0
   > Could not GET 'https://repo1.maven.org/maven2/org/ros/rosjava_messages/roscpp/1.11.21/roscpp-1.11.21.pom'.
      > Connection to https://repo1.maven.org refused

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[100%] Built target android_app_communication_generate_messages_java_gradle
Scanning dependencies of target android_app_communication_generate_messages
[100%] Built target android_app_communication_generate_messages

我们编译rosjava源码的意义在于编译属于我们自己的项目,我们需要获得编译生成的jar包,我们的安卓app代码引用了该jar包才能与ROS机器人进行通信,才能控制我们的ROS系统,例如我在rosjava中创建了ros_arduino_msgs软件包,目录结构如下图所示:

当我们把整个rosjava代码编译完成后,需要在哪里找到编译完成的jar包呢?查看下图:

接下来就可以将该jar包复制到安卓app源码相应目录的libs下,再配置一下引用该jar包即可。


0x04 android源码简析

android_core为配套的安卓助手端app的源码,源码的目录结构如下:

在了解了安卓源码的目录结构后,就准备在android studio中打开编译了,具体的配置android studio环境需要大家提前配置好,如果有需要的话会专门再发布一篇教程来指导大家如何安装android studio配置java环境。下面的过程是你已经配置好android studio了,然后将该安卓源码导入编译即可,首先是打开android studio截图:

当接上手机后,点击项目旁边的三角运行按钮即可编译整个项目,然后将编译生成的apk安装进手机中:

 

当连接成功后app的界面如下图所示:


0x05 arduino源码解析

arduino的代码结构如下图所示:

在了解各个arduino代码后开始准备在arduino IDE中打开项目进行编译,这里我们打开三轮全向移动底盘arduino代码查看:


0x06 问题反馈

由于本人能力有限,如果大家在此过程中有任何问题,可以直接给我评论或者可以关注ROS小课堂的官方微信公众号,在公众号中给我发消息,我基本上每天都会处理公众号中的留言!当然,如果你要是顺便给ROS小课堂打个赏,我也会感激不尽的!


2 条评论

panyj1993 · 2017-12-26 23:19

我的小车上电运行了bringup.lauch之后小车就转的飞快,在我的电脑上打开teleop调节速度也没有用,然后树莓派上关闭了bringup.launch之后小车还在转,这是什么原因?

 

    admin · 2017-12-27 09:16

    建议先调试一下下位机部分代码是否正常运行,当通过往下位机串口发送指令,小车的三个车轮可以正常运行后再使用bringup.launch文件启动控制

     

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d 博主赞过:
跳至工具栏