Run Astrobee Simulator on your local machine. Set up a simple simulation environment locally without randomness modules (Phases/targets randomness generator, air flow simulator and navigation errors) or a judge module.
- See Android Emulator setup for Astrobee Simulator for details.
1. Build Simulator with Docker
-
Install Docker https://docs.docker.com/engine/install/ubuntu/
-
Download
krpc5_simulator
from https://jaxa.krpc.jp/download.html-
build.sh
-
run.sh
-
#!/bin/bash
##############################
# Static values
#
rootdir=$(dirname "$(readlink -f "$0")")
cd $rootdir
bootstrap_dir=${rootdir}/bootstrap
crew_operation_dir=${rootdir}/crew_operation_module
OBJECT_NAME_ARRAY=("lostitem1" "lostitem2" "lostitem3" "lostitem4" "lostitem_target")
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
##############################
# Run Simulator
#
ROS_IP=$(getent hosts llp | awk '{ print $1 }')
docker run -it --rm --name astrobee \
--volume=$XSOCK:$XSOCK:rw \
--volume=$XAUTH:$XAUTH:rw \
--volume=${bootstrap_dir}:/tmp/bootstrap \
--volume=${crew_operation_dir}:/tmp/crew_operation_module \
--env="XAUTHORITY=${XAUTH}" \
--env="DISPLAY" \
--env="ROS_MASTER_URI=http://${ROS_IP}:11311" \
--env="ROS_HOSTNAME=${ROS_IP}" \
--user="astrobee" \
--privileged \
--network=host \
krpc/astrobee_sim-base:5.0.0 \
/astrobee_init.sh bash /tmp/bootstrap/run.sh
- Pull Docker image
docker pull mizanul/krpc_astrobee_sim-base:5.0.0
- Copy hostname
hostname -I
-
Edit
run.sh
- Replace instances of
ROS_IP
with hostname - Change name of Docker image to
mizanul/krpc_astrobee_sim-base:5.0.0 \
- Replace instances of
-
Edit hosts file to set up the network
Sudo nano /etc/hosts
#127.0.0.1 hlp
#127.0.0.1 mlp
#127.0.0.1 llp
10.42.0.36 hlp
10.42.0.35 mlp
10.42.0.34 llp
- run simulation
bash run.sh
- Setting the environment variables
Export ANDROID_PATH=${HOME}/astrobee_android
export EMULATOR=$HOME/Android/Sdk/tools/emulator
export AVD=”AstrobeeAndroidSim”
2. Set up Android Emulator for Astrobee Simulator
Set up Android Emulator to run the SDK (only needed for local simlution). See https://github.com/nasa/astrobee_android/blob/master/emulator.md#2-add-an-emulator for more details.
Create an AVD (Android Virtual Device) as follows:
- Launch Android Studio.
- Select [Tools] → [AVD Manager].
- In the Android Virtual Device Manager window, click [Create Virtual Device…].
- Select device Nexus 5 (Resolution 1080x1920) and click [Next].
- Select the [x86 Images] tab:
- Choose Nougat/API Level 25/ABI x86_64/Android 7.1.1 (NO Google APIs), then click [Next].
- Note: Download the system image now if needed.
- Set the AVD name to “AstrobeeAndroidSim”.
- Click [Finish].
- Launch AVD
- In the Android Virtual Device Manager window, you will see “AstrobeeAndroidSim” in the list.
- Click the Play button in the Action column.
Optional: Start emulator from command line
https://developer.android.com/studio/run/emulator-commandline
- Get list of AVD names from Android home directory
- You can override the default home directory by setting the ANDROID_SDK_HOME environment variable that specifies the root of the user-specific directory where all configuration and AVD content is stored.
- You can set the environment variable in the terminal window before launching a virtual device or through your user settings in the operating system. For example, in your .bashrc file on Linux.
emulator -list-avds
- Launch emulator
emulator -avd avd_name [ {-option [value]} … ]
# 2nd way:
emulator @avd_name [ {-option [value]} … ]
# Example (Run emulator window within Android studio with options: -qt-hide-window -grpc-use-token -idle-grpc-timeout):
/Users/janedoe/Library/Android/sdk/emulator/emulator -avd Pixel8_API_34 -netdelay none -netspeed full -qt-hide-window -grpc-use-token -idle-grpc-timeout
3. Build the Guest Science Manager APK
To run your program, you must install the Guest Science Manager APK. (see details at https://github.com/nasa/astrobee_android/blob/master/guest_science_readme.md )
- Clone the Astrobee Android package from GitHub.
export ANDROID_PATH=${HOME}/astrobee_android
git clone https://github.com/nasa/astrobee_android.git
git checkout a8560ab0270ac281d8eadeb48645f4224582985e
- Execute the following commands to build the Guest Science Manager APK.
cd $ANDROID_PATH/core_apks/guest_science_manager
ANDROID_HOME=$HOME/Android/Sdk ./gradlew assembleDebug
4. Set Up the network
Setup the network between the Kibo-RPC Simulator and the Android Emulator. See https://github.com/nasa/astrobee_android/blob/master/emulator.md for details.
Install ADB
ADB (Android Debug Bridge) allows the user to access physical and emulated Android devices, push/pull files, and manage applications. Android Studio already includes this program. However, it is important you install it as a separate package. In a terminal, please do the following:
sudo apt-get install adb
Set HOST Network
Edit HOSTS file
- Open hosts file
sudo nano /etc/hosts
- Add 3 lines (from line 4 to line 6)
127.0.0.1 localhost
127.0.1.1 ubuntu
10.42.0.36 hlp
10.42.0.35 mlp
10.42.0.34 llp
[...]
Set Environment Variables
- in WSL2
export WIN_USERPROFILE=/mnt/c/Users/{username}/
export ANDROID_PATH=~/projects/kiborpc/krpc5_simulator/astrobee_android
export EMULATOR=$WIN_USERPROFILE/AppData/Local/Android/Sdk/emulator/emulator.exe
export AVD="AstrobeeAndroidSim"
- To make these commands available in all new terminal sessions, you can add them to
bashrc
and source it
source ~/.bashrc
- If you need to switch emulator, you can get the names here
$EMULATOR -list-avds
AstrobeeAndroidSim
Pixel_3a_API_34_extension_level_7_x86_64
Pixel_4_XL_Edited_1_API_31
Pixel_6_API_33
Setting network bridge and running the emulator
In order to correctly set up the communication between the Android emulator and the rest of the simulator, we need to run a script that takes care of that.
- Launch the emulator script which will set the HOST network. Provide your super user password if requested.
cd $ANDROID_PATH/scripts
./launch_emulator.sh
- Note: To run emulator directly:
- In Windows Terminal
cd %USERPROFILE%\AppData\Local\Android\Sdk\emulator
emulator.exe -avd AstrobeeAndroidSim
- In WSL
export EMULATOR=$WIN_USERPROFILE/AppData/Local/Android/Sdk/emulator/emulator.exe
$EMULATOR -avd $AVD
- Show running emulators
- Windows:
tasklist | findstr qemu
# qemu-system-i386.exe 23896 Console 1 679,128 K
- debug.
- In WSL:
ps aux | grep qemu
adb devices # Other way