ROS学习笔记之——基于ROS的Android开发

47 篇文章 13 订阅

之前博客已经介绍了在linux下安装Android studio《基于linux系统安装Android Studio》,同时也实现了用手机控制turtlebot3的移动。本博文来系统性的学习一下Android与ROS联合开发~

目录

ROSJAVA

ROSAndroid

在Android中使用ROS

ROS与Android项目实例实践

参考资料


ROSJAVA

ROSjava为ros在java中的通信提供了一个客户端库,以及一系列的核心工具及驱动。

rosjava_core,它是用纯JAVA实现ROS。它提供了一个客户端库是JAVA程序可以快速的调用ROS的Topics,Services, and Parameters。其中一个最重要的特点就是对Android的友好性,可以在Android上进行rosjava的开发。

rosjava的一些官方代码可见:https://github.com/rosjava

ROS Java是指以Java语言运行的ROS客户端库。我们先设置运行Java所需的选项。需要的功能包是Java SE Development Kit(JDK)(但是在安装android studio的时候应该会自动安装了,如果没有可以参考下)

之前博文也介绍了怎么安装JDK(基于linux系统安装Android Studio

$ sudo apt-get install openjdk-8-jdk
$ echo export PATH=${PATH}:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/android-studio/
bin >> ~/.bashrc
$ echo export ANDROIS_HOME=/opt/android-sdk >> ~/.bashrc
$ source ~/.bashrc

以下命令下载用于ROS Java中的构建所需的工具。之后,安装并构建一个包含ROSJava系统和示例的功能包。这里的android_core目录是和前面出现的catkin_ws目录具有同样意义的目录。

sudo apt-get install ros-kinetic-rosjava-build-tools
$ mkdir -p ~/android_core
$ wstool init -j4 ~/android_core/src https://raw.github.com/rosjava/rosjava/kinetic/
android_core.rosinstall
$ source /opt/ros/kinetic/setup.bash
$ cd ~/android_core
$ catkin_make

ROSjava环境的搭建可以参考(https://jimmylee05.github.io/2018/11/12/ROSJava%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/

ROSAndroid

android_core一个集合rosjava组件和范例的ROS开发应用。

首先需要安装Android studio(可参考android/kinetic/Android Studio/Download - ROS Wiki以及博文《基于linux系统安装Android Studio》)

也可以参考书籍《ROS_Robot_Programming_EN》

在Android中使用ROS

在Android中使用ROS | 蓝鲸ROS机器人论坛

在Android中使用ROS_bluewhalerobot的博客-CSDN博客)

在Android中使用ROS相关的配置方式可以有两种。

  • 一种是在ROS环境中使用
  • 另一种是给普通的Android App添加上ROS的依赖库。也即是可以在开发机器没有安装ROS的条件下进行开发。

由于本人已经在装有ROS的ubuntu中搭建了Android系统,故此就不再采用该方式了,有兴趣的可以参考链接

ROS与Android项目实例实践

github工程https://github.com/ros-autom/RobotCA/tree/kinetic/src/android_foo是一款可以控制机器人的APP。但是配置起来有点麻烦~~~

首先有些网页在大陆访问比较困难,为此修改build.gradle文件

/*
 * Copyright (C) 2014 Mike
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.3'
}

buildscript {

//    apply from: "https://github.com/rosjava/android_core/raw/kinetic/buildscript.gradle"
//    apply from: "https://github.com/rosjava/rosjava_bootstrap/raw/kinetic/buildscript.gradle"

    String rosMavenPath = System.getenv("ROS_MAVEN_PATH")
    String rosMavenRepository = System.getenv("ROS_MAVEN_REPOSITORY")
    repositories {
        if (rosMavenPath != null) {
            rosMavenPath.tokenize(":").each { path ->
                maven {
                    // We can't use uri() here because we aren't running inside something
                    // that implements the Script interface.
                    url "file:${path}"
                }
            }
        }
        maven {
            url "http://repository.springsource.com/maven/bundles/release"
        }
        maven {
            url "http://repository.springsource.com/maven/bundles/external"
        }
        if (rosMavenRepository != null) {
            maven {
                url rosMavenRepository
            }
        }
        maven {
            url "https://github.com/rosjava/rosjava_mvn_repo/raw/master"
        }
//        google()
        maven {
            url 'https://maven.google.com'
        }
        jcenter()
    }
    dependencies {
        classpath "org.ros.rosjava_bootstrap:gradle_plugins:[0.3,0.4)"
    }

    dependencies {
        classpath "com.android.tools.build:gradle:3.2.1"
    }

    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }

    dependencies {
        //Add this to fix the gradle plugin issues
        classpath 'com.android.tools.build:gradle:1.5.0'

        // TEST
        classpath 'junit:junit:4.12'
        classpath 'org.mockito:mockito-core:1.10.19'
    }
}

apply plugin: 'catkin'


allprojects {
    /* A github url provides a good standard unique name for your project */
    group 'com.github.sccapstone.robotca'
    //version = project.catkin.pkg.version
}

subprojects {
    /*
     * The android plugin configures a few things:
     *
     *  - local deployment repository : where it dumps the jars and packaged artifacts)
     *  - local maven repositories    : where it finds your locally installed/built artifacts)
     *  - external maven repositories : where it goes looking if it can't find dependencies locally
     *  - android build tools version : which version we use across the board
     *
     * To modify, or add repos to the default external maven repositories list, pull request against this code:
     *
     *   https://github.com/rosjava/rosjava_bootstrap/blob/indigo/gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosPlugin.groovy#L31
     *
     * To modify the build tools version, pull request against this code:
     *
     *   https://github.com/rosjava/rosjava_bootstrap/blob/indigo/gradle_plugins/src/main/groovy/org/ros/gradle_plugins/RosAndroid.groovy#L14
     */
    apply plugin: 'ros-android'

    afterEvaluate { project ->
        android {
            // Exclude a few files that are duplicated across our dependencies and
            // prevent packaging Android applications....
            packagingOptions {
                exclude "META-INF/LICENSE.txt"
                exclude "META-INF/NOTICE.txt"
            }
        }
    }
}

然后在配置的时候,会存在一下网络打不开的情况

运行下面命令

sudo code /etc/hosts --user-data-dir

通过下面网站查询对应网页的ip

https://www.ipaddress.com/

然后修改

配置的时候还可能出现xml1.0与2.0的匹配情况。修改对应的xml文件即可

然后就可以安装此app~

注意:千万千万不要手贱按更新~一旦更新了,会发现gradle配置不对,然后工程无法运行~至于解决办法,可以通过project structure修改gradel ersion

参考资料

rosjava - ROS Wiki

android - ROS Wiki

https://github.com/rosjava

https://github.com/rosjava/android_apps

Turtlebot与Android-利用Rocon Remocon app建立互动连接 - 创客智造

ROSjava探索(更新完结)_DavidHan008-CSDN博客

【笔记】Android上ROS开发介绍与安装简介_F_season的专栏-CSDN博客

  • 5
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值