6975 views|3 replies

654

Posts

26

Resources
The OP
 

42 "Wanli" Raspberry Pi car - ROS learning (Android uses ROSBridge to control the little turtle) [Copy link]

 
This post was last edited by lb8820265 on 2022-11-8 23:14

Previously, we used ROSBridge to control the little turtle through the web page . Here we will introduce how to control the little turtle using an Android phone.

1. Create a new ROSBridge project from scratch

Learning from Android source code is not the best method. Due to different environments, direct compilation may not be successful, and porting to your own project may not be successful. Therefore, here we introduce creating a new ROSBridge project from scratch.

0. Download source code

Download link at the end of the post.

1. Create a new AS project

This post uses Android Studio 4.1. Create a blank project with the package name "Lb_ROSBridge_Turtle".

2. Copy the sample files to the new project

Copy the files in the "libs" folder to the corresponding location of the new project.

Copy the "jilk" folder to the corresponding location of the new project.

Replace the "activity_main.xml" layout file to the corresponding location of the new project. If the package name is different, remember to modify the package path of tools:context in the file.

Replace the "MainActivity.java" and copy the "RCApplication.java" files to the corresponding locations of the new project. If the package names are different, remember to modify the package name in the first line of the file.

3. Modify the "AndroidManifest.xml" file

Add permissions

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Associate Application

android:name="com.example.lb_rosbridge_turtle.RCApplication"

Allow external components to start (required on Android 12 and above phones)

android:exported="true"

4. Modify the "build.gradle" file

Add libs folder library path

implementation fileTree(include: ['*.jar'], dir: 'libs')

2. ROSBridge Workflow

All the writing is in the "MainActivity.java" file.

1. Register EventBus to receive messages

EventBus.getDefault().register(this);

2. Call connect to connect to the Raspberry Pi server

connect(String ip, String port)

3. Get the connected Rosbridgeclient class instance

client = ((RCApplication)getApplication()).getRosClient();

4. Send data to the server

client.send(msg);

Subscribing and publishing information are the same command.

5. Get server data

onEvent(final PublishEvent event)

The above is just the main process, for detailed code, see the source code.

3. Operation and Demonstration

Raspberry Pi Server Operation

1. Start the kernel

roscore

2. Start the turtle

rosrun turtlesim turtlesim_node

3. Start the rosbridgea service

roslaunch rosbridge_server rosbridge_websocket.launch

Mobile operation

0. Run the app

You can use online simulation or directly install the APP.

1. Enter the Raspberry Pi IP

The mobile phone and Raspberry Pi need to be in the same LAN.

2. Click "Connect"

If the connection is normal, the connection status will show "Connected"

3. Click "Subscribe to Location"

That is, send a subscription command, and then the Raspberry Pi will keep sending location information to the mobile phone.

4. Input control parameters

Slide the slider to select the control parameters: straight speed, lateral speed and turning speed.

5. Click Publish

After the control parameters are released, the Raspberry Pi turtle will start moving according to the motion parameters.

4. Source Code

GitHub:https://github.com/wanli-car/Examples/tree/master/Android/Lb_ROSBridge_Turtle

Gitee:https://gitee.com/wanli-car/Examples/tree/master/Android/Lb_ROSBridge_Turtle

The APK installation package is attached in the post.

image-20221108222814-4.png (8.44 KB, downloads: 0)

image-20221108222814-4.png

image-20221108222814-1.png (48.92 KB, downloads: 0)

image-20221108222814-1.png

Lb_ROSBridge_Turtle.apk

2.23 MB, downloads: 6

Lb_ROSBridge_Turtle.apk

2.23 MB, downloads: 3

This post is from Innovation Lab

Latest reply

I bought a Raspberry Pi 4B 2G version, but unfortunately I was so busy that it was covered in dust after I bought it. And the price was reduced by more than half later.  Details Published on 2023-11-25 01:54
Personal signatureQQ:252669569
 
 

6552

Posts

0

Resources
2
 

First create a new ROSBridge project file. It is a good habit to learn ROS.

This post is from Innovation Lab
 
 
 

34

Posts

0

Resources
3
 

First create a new ROSBridge project file. It is a good habit to learn ROS.

This post is from Innovation Lab
 
 
 

1462

Posts

0

Resources
4
 
I bought a Raspberry Pi 4B 2G version, but unfortunately I was so busy that it was covered in dust after I bought it. And the price was reduced by more than half later.
This post is from Innovation Lab
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list