How to Use Raspberry Pi Model 3B to Control Alpha 1 Pro · How to Use Raspberry Pi Model 3B to...
Transcript of How to Use Raspberry Pi Model 3B to Control Alpha 1 Pro · How to Use Raspberry Pi Model 3B to...
How to Use Raspberry Pi Model 3B to
Control Alpha 1 Pro
Version 1.0
Note: This article is a tutorial for novices to use Raspberry Pi to connect with
Alphal 1 Pro humanoid robot, which only teaches how to build the connection
via Bluetooth on board, and how to control the robot motions based on the
corresponding protocols. Assume that the readers are already familiar with the
basic operations of Alpha 1 Pro and Raspberry Pi, and has some knowledge of
programming, etc.
Update Time Author Version
2017/06/16 Nick, CUI Ning V1.0, original release
1. How to Control Alpha 1 Pro Robot
Generally, there are several ways to control Alphal 1 Pro:
Use the official PC software for motion editions. The PC software can be
downloaded from the link below:
http://www.cn.ubtrobot.com/product/aboutinfo4.html
However, only the motions could be edited through the PC software, which
has no opened interfaces for developers.
If you want to use Raspberry Pi or other controllers to communicate with
Alpha 1 Pro, the Bluetooth inside the Alpha 1 Pro should be used.
Download the communication protocol for bluetooth from this link:
http://www.cn.ubtrobot.com/product/aboutinfo4.html
There are also three ways to control Alpha 1 Pro robot via Bluetooth:
Use an additional USB-to-Bluetooth communication module plugged
into Raspberry Pi
Use the Bluetooth on Raspberry Pi directly
Open the cover of Alpha 1 Pro, bypass the Bluetooth module on the
controller PCB, and connect with Raspberry Pi’s UART port through
Wires.
In the following, we will introduce how to use the bluetooth on Raspberry Pi
to connect and control Alpha 1 Pro humanoid robot.
2. Motion Editions and Bluetooth
Communication Protocol
Although there are some commands in the Bluetooth protocol to control the
actions of Alpha 1 robot servo by servo, it is difficult to edit some complicated
motions through single servo motor control; therefore, if you want to create your
own actions, the official PC software is recommended. After creating and
editing, the action will be saved in the storage in the format of hts file. The name
of the action file can be listed through a unique Bluetooth command. Once the
action list got, you can use the action command to control the robot perform the
corresponding actions edited.
2.1 How to edit the actions with PRP programming
Step 1: Alpha 1 Pro is able to be connected with your PC via USB-to-mini USB
cable. Install the PC software on your computer, open it, register an account,
and login. (If you want to see the existed action files in the storage, click the
Synchronize button on the top menu and then click the turning your robot to the
U-disk mode icon on the bottom.)
Step 2: Get familiar with the programming interface. The picture of the robot
head in the top right corner shows the connect status between the PC and the
robot.
Step 3: Now we start to use PRP to edit the actions.
PRP, Pose Record Playback, is a programming method developed by UBTech
Robot. The principle of it is to divide the action sequence frame by frame, and
record all the servo angles in each frame, and then make the robot playback
the action sequence following the action frames recorded.
For example, let’s edit the action of swing arms:
Click the button of adding a new action frame
Click the button of recording the servo angles in the arms. Then the servos
in arms will be powered off, and move the arms to the target pose you want
to edit. Then click the button of recording the servo angles in the arms again.
Click the button of adding a new action frame again.
Click the playback button to perform the actions recorded.
2.2 Bluetooth Communication Protocol
Both parties to communicate with each other correctly and efficiently should
be based on a regulated protocol. According to the communication protocol
document downloaded from the official website of UBTech Robot, many
functions could be achieved.
Here list some main commands. Download a Serial Port Bluetooth App on
your Android mobile phone, connect with Alpha 1 Pro via bluetooth and send
the commands below to test it.
Acquisition of action list:
Transmit: FB BF 06 02 00 08 ED
Receive: [Note] please decode the action name according to the bluetooth
communication protocol
67 65 74 20 75 70 D0
48 61 70 70 79 20 42 69 72 74 68 64 61 79 EC
BA F3 CD CB (后退/move backwards)
D0 A1 C6 BB B9 FB (小苹果舞蹈/Dance with a music)
D7 F3 B3 F6 C8 AD
C4 BE C2 ED CD C0 B3 C7 BC C7
BD AD C4 CF 73 74 79 6C 65
D7 D4 CE D2 BD E9 C9 DC 2D BC D3 B3 A4 B0 E6
D7 D4 CE D2 BD E9 C9 DC
Execution of action:
Transmit example1: FB BF 09 03 BA F3 CD CB 51 ED (后退)
Transmit example2: FB BF 0B 03 D0 A1 C6 BB B9 FB B4 ED (小苹果)
Powering off of all the servos:
Transmit: FB BF 06 0C 00 12 ED
Controlling the actions of a servo:
FB BF 0A 22 10 57 0A 00 0A A7 ED 16 号舵机转到 87°位置(16 号舵机的角度转动范
围为 57°至 111°)/ Rotate the servo motor (ID=16) to the target position at 87°
Acquisition of robot status:
Transmit: FB BF 06 0A 00 10 ED
Receive: FB BF 07 0A 00 01 12 ED 声音状态/ Speaker
FB BF 07 0A 01 00 12 ED 播放状态/ Play
FB BF 07 0A 02 80 93 ED 音量 / Volume
FB BF 07 0A 03 01 15 ED 舵机灯状态 / Servo LEDs
FB BF 07 0A 04 01 16 ED TF 卡状态 / TF storage
Acquisition of the angles of a servo:
Transmit: FB BF 06 24 10 3A ED 16 号舵机
Receive: FB BF 07 24 10 6F AA ED 6F:111°
FB BF 07 24 10 57 92 ED 57: 87°
FB BF 07 24 10 3F 7A ED 3F: 63°
FB BF 07 24 10 39 74 ED 57°
There are still some other functional commands in the Bluetooth
Communication Protocol document, and you can test them if your project needs
to.
3. Bluetooth Configurations of
Raspberry Pi
3.1 Add SPP to your Raspberry Pi
The controller board of Alpha 1 Pro has a Bluetooth module, which supports
Serial Port Profile. Therefore, it is imperative to configure your Raspberry Pi to
be compatible with SPP.
Commands: nano /etc/systemd/system/dbus-org.bluez.service
Modify the two lines of codes to:
ExecStart=/usr/lib/bluetooth/bluetoothd -compat
ExecStartPost=/usr/bin/sdptool add SP
Check the Bluetooth Service:
Command: hciconfig
Please refer to the link below to configure the SPP service:
http://blog.csdn.net/wanyeye/article/details/52909869
3.2 Connect the Raspberry Pi with Alpha 1 Pro
Command: rfcomm bind hci0 <Alpha 1 pro bluetooth mac address>
(Note: don’t use “connect” command)
4. Example
Here is an example source code to control the Alpha 1 pro via Bluetooth:
After binding with the Bluetooth on Alpha 1 Pro, compile and link the c
program file test_spp_client, and then execute it. Alpha 1 Pro will receive the
command to dance with music.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd,ret,i;
char buf[]={0xfb,0xbf,0x06,0x01,0x00,0x07,0xed};
char buf_1[] = {0xfb,0xbf,0x06,0x02,0x00,0x08,0xed};
char buf_2[] =
{0xfb,0xbf,0x0b,0x03,0xD0,0xA1,0xC6,0xBB,0xB9,0xFB,0xB4,0xED};
char rbuf[99];
fd = open("/dev/rfcomm0", O_RDWR);
if(fd < 0){ printf("open dev/rfcomm error!\r\n");
return -1;}
//write(fd,buf_1,sizeof(buf_1));
//write(fd,buf_1,sizeof(buf_1));
write(fd,buf_2,sizeof(buf_2));
printf("write end!\r\n");
while(1){
ret = read(fd,rbuf,sizeof(rbuf));
printf("recv ret:%d\r\n",ret);
for(i=0; i<ret; i++)
printf("[%d]:%x ",i, rbuf[i]);
sleep(1);
}
close(fd);
}