Important
This is the repository for the old smabo.
It is no longer under active development, and this repository is deprecated.
The repository for the greatly powered-up new smabo is below.
How to build a robot that holds a smartphone【smabo】 (Japanese)

This is a repository related to smabo, a robot that holds a smartphone.
- smabo
- What is smabo
- Setting up smabo
- How to use smabo
- Controlling the robot arm
smabo is a robot that holds a smartphone, and it can do a variety of things, such as:
- Navigation
- Motion planning
- Image processing
- Remote control
- Deep learning
- Bipedal walking
19.mp4
This repository is intended to bring together code and other resources related to smabo.
For detailed setup instructions for smabo, please see the following blog (in Japanese).
How to build a robot that holds a smartphone【smabo】
This README only covers the basic environment setup and usage.
Please install ROS2 (Humble) by referring to the following site. https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html
Running source /opt/ros/humble/setup.bash lets you use the ros2 command, but typing it every time you open a terminal is tedious, so run the following command.
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrcInstall the GPIO package.
sudo apt update -y && sudo apt install -y \
python3-rpi.gpioAlso, please set up the RPi.GPIO package so it can be used without sudo, referring to the following site.
【Raspberry Pi + Ubuntu】How to fix the "failed to add edge detection" error when using add_event_detect without sudo (Japanese)
Install the other required packages.
pip install adafruit-pca9685 # Package for the servo driver pca-9685pip install opencv-contrib-python # openCV (image processing)pip install ipget # Get the IP addresspip install readchar # Single-character inputpip install flask # flask (web application framework)Create a workspace for smabo with the following command.
mkdir -p smabo_ws/srcClone this repository with the following command.
cd ~/git clone https://github.com/akinami3/smabo.gitNext, copy the smabo packages into the workspace's src directory with the following command.
cp -r ~/smabo/smabo_pkgs ~/smabo_ws/srcIn addition to the smabo-related packages, also clone "ROS-TCP-Endpoint," the package needed to communicate with Unity over ROS2 (used for communication between the smartphone and the Raspberry Pi).
cd ~/smabo_ws/srcgit clone -b dev-ros2 https://github.com/Unity-Technologies/ROS-TCP-Endpoint.gitBuild the workspace with the following command.
cd ~/smabo_wscolcon build --symlink-installNext, make it so the built packages can be launched via the ros2 command.
source ~/smabo_ws/install/setup.bashRunning this command every time you open a terminal is tedious, so add it to .bashrc as well.
echo "source ~/smabo_ws/install/setup.bash" >> ~/.bashrcDownload the "SmartPhoneRobot.apk" from the repository to your smartphone and install it.
This section explains how to use smabo.
Launch the server for communicating between Unity and ROS with the following command.
ros2 run ros_tcp_endpoint default_server_endpointOn your smartphone, launch the installed smart_phone_robot (smabo) app.
When you launch the app, an options screen for entering the IP address and port number is displayed.
- ip address: the Raspberry Pi's IP address
- port: 10000
Enter these values and click the "Connect" button.
After clicking the button and waiting a moment, if "connected!!!!!!!" is displayed, the connection is complete.
Note
If, after trying several times, "not connected" keeps being displayed, check whether the Raspberry Pi and the smartphone may be connected to different networks.
The following command launches the node that changes smabo's facial expression.
ros2 run smabo_pkg impression_pubOnce the node is launched, you can change smabo's expression by entering an integer between 0 and 5.
The following command launches the node that retrieves the smartphone's gyroscope data.
ros2 run smabo_pkg gyro_subThe following command launches the node that retrieves the smartphone's acceleration data.
ros2 run smabo_pkg accel_subThe following command launches the node that retrieves the smartphone's compass data.
ros2 run smabo_pkg magnetic_subConnect the right arm's servo to pin 6 and the left arm's servo to pin 7 of the pca9685 before proceeding.

Change the permissions of i2c-1.
sudo chmod 666 /dev/i2c-1Run the program, and entering an integer between -90 and 90 degrees moves smabo's arm to the specified angle.
cd ~/smabo/simple_codepython3 pca9685_simple_hand.pyLaunch the node that controls the pca9685.
ros2 run smabo_pkg pca9685_controllerNext, open a new terminal and launch the node that controls smabo's arm.
ros2 run smabo_pkg simple_hand_angle_commanderWith this node launched, entering an integer between -90 and 90 degrees moves smabo's arm to the specified angle.
Change the permissions of i2c-1.
sudo chmod 666 /dev/i2c-1Connect the head's servo to pin 5 of the pca9685 before proceeding.
Launch the node that controls the pca9685.
ros2 run smabo_pkg pca9685_controllerNext, open a new terminal and launch the node that controls smabo's head.
ros2 run smabo_pkg head_arrow_key_commander With this node launched, pressing the "z" key rotates it to the left, and pressing the "x" key rotates it to the right.
An hc-sr04 is used as the ultrasonic sensor.
Run the code that retrieves distance data from the ultrasonic sensor.
cd ~/smabo/simple_codepython3 ultrasonic_sr04.py When you run the code, the distance (cm) measured by the ultrasonic sensor is displayed as shown below.
13.17 cm
13.18 cm
13.21 cm
13.20 cm
13.21 cmLaunch the node that retrieves distance data from the ultrasonic sensor.
ros2 run smabo_pkg ultrasonic_sensorWhen you run the code, the distance (m) measured by the ultrasonic sensor is displayed as shown below.
[INFO] [1704560652.946915129] [ultrasonic_sensor]: distance: 0.04410195350646973 m
[INFO] [1704560652.951719651] [ultrasonic_sensor]: distance: 0.1263386607170105 m
[INFO] [1704560653.041953099] [ultrasonic_sensor]: distance: 0.12637817859649658 m
[INFO] [1704560653.143156803] [ultrasonic_sensor]: distance: 0.12622010707855225 m
[INFO] [1704560653.242842910] [ultrasonic_sensor]: distance: 0.12665480375289917 mChange the permissions of video0.
sudo chmod 666 /dev/video0Run the code that displays the images captured from the camera on a flask server.
cd ~/smabo/simple_codepython3 cam_stream_on_flask.pyAccessing the address shown in the terminal (192.168.***.***:5000/) displays the images captured from the camera.
Launch the node that captures images from the camera.
ros2 run smabo_pkg cam_stream Open a new terminal and launch the node that displays, via flask, the images subscribed to from the /image topic.
ros2 run smabo_pkg flask_image_displayAccessing the address shown in the terminal (192.168.***.***:5000/) displays the images captured from the camera.
Run the code that controls smabo as a mobile robot.
cd ~/smabo/simple_codepython3 control_move_smabo.pyYou can control it by pressing the following keys on the keyboard.
q w e r
a s d
z x c v
s: stop
w: move forward
x: move backward
d: rotate right (in place)
a: rotate left (in place)
e: left wheel forward only
c: left wheel backward only
q: right wheel forward only
z: right wheel backward only
r: speed up
v: slow down
Launch the node that controls the DC motors for the mobile robot.
ros2 run smabo_pkg move_robot_dc_controller Open a new terminal and launch the node that sends driving commands to the DC motor control node.
ros2 run smabo_pkg move_robot_commander You can control it by pressing the following keys on the keyboard.
q w e r
a s d
z x c v
s: stop
w: move forward
x: move backward
d: rotate right (in place)
a: rotate left (in place)
e: left wheel forward only
c: left wheel backward only
q: right wheel forward only
z: right wheel backward only
r: speed up
v: slow down
Change the permissions of i2c-1.
sudo chmod 666 /dev/i2c-1Connect each servo to the following pins of the pca9685:
- link1 (shared with the head servo): pin 5
- link2: pin 13
- link3: pin 14
- gripper: pin 15
Launch the node that controls the pca9685.
ros2 run smabo_pkg pca9685_controllerNext, open a new terminal and launch the node that sets each link and the gripper of the robot arm.
ros2 run smabo_pkg link3_robot_arm_commanderYou can control it by pressing the following keys on the keyboard.
q w e
a s d
z x
z: rotate link1 in the positive direction
x: rotate link1 in the negative direction
q: rotate link2 in the positive direction
a: rotate link2 in the negative direction
w: rotate link3 in the positive direction
s: rotate link3 in the negative direction
e: open the gripper
d: close the gripper







