This application, which implements a mobile inverted pendulum robots, is designed to show how to develop a Motion Control using embARC.
VIDEO URL: DEMO VIDEO
- Hardware and Software Setup
- User Manual
This project was successful in achieving a two-wheeled autonomous robot based on the inverted pendulum model.EMSK works as controller, it will deal with sensor datas and interact with user via bluetooth. We can view all data on serial terminal, and sent instructions to the robot to change its motion mode.
The robot can keep itself upright even if there is a great disturbances.
- Linear Motion
Under upright condition, the robot has excellent ability to linear motion.
- Angular Rotation
Not only linear motion, but also angular rotation can be implemented.
- Over the Seesaw
Based on the above, the robot can autonomously through the seesaw
Hardware and Software Setup
- 1 DesignWare ARC EM Starter Kit(EMSK V2.3)
- 2 BLE module(HC-05)
- 1 USB To TTL module(CP2102)
- 1 IMU module(MPU6050)
- 1 Motor Driver
- 1 Voltage Conversion module(7805)
- 1 NiCd Battery
- 1 SD Card
- 1 SPI to QEI AND PWM Expanding-board
- 1 Robot Platform
- ARC GNU Toolset 2017.03
- Serial port terminal, such as putty, tera-term or minicom
- Connect BLE HC-05 module to Pmod J1(Using UART interface)
- Connect IMU MPU6050 module to Pmode J2(Using I2C interface)
- Connect Expansion Board to Pmode J6, J5(Using J6 SPI interface, J5 using for mechanical fixing)
Before running this application
Download source code of invert-pendulum from github, and ensure install a serial port terminal and arc-gnu toolset in your PC. The hardware resources are allocated as following table.
|MPU6050||Gyroscope and acceleration sensor|
|HC-05||Provide bluetooth connection|
|CP2102||USB TO TTL|
|MC7805||Linear Voltage Regulator|
|ROBOTS PLATFORM||integrated module|
Run This Application
Here take EMSK2.3, CUR_CORE = arcem7d with GNU Toolset for example to show how to run this application.
- We need to use embARC 2nd bootloader to automatically load application binary for different EMSK and run. See example/bootloader Example for reference.
- Open your serial terminal such as Tera-Term on PC, and configure it to right COM port and 115200bps.
- Interact using EMSK and serial port terminal.
Selected FreeRTOS in /application/invered_pendulum/scr/makefile, then you can use FreeRTOS API in your application:
#Selected OS OS_SEL ?= freertos
Target options about EMSK and toolchain:
BOARD ?= emsk BD_VER ?= 23 CUR_CORE ?= arcem7d TOOLCHAIN = gnu
The relative series of the root directory, here the path of the makefile is /application/invered_pendulum/scr/makefile:
# # root dir of embarc # EMBARC_ROOT = ../../../..
Directories of source files and header files, notice that it is not recursive:
# application source dirs APPL_CSRC_DIR = . ./TskDbg ./Queue ./TskMotor ./drivers ./TskTop ./FastMath_Table APPL_ASMSRC_DIR = . # application include dirs APPL_INC_DIR = . ./TskDbg ./Queue ./TskTop ./drivers ./TskMotor ./FastMath_Table
See embARC Example User Guide, "Options to Hard-Code in the Application Makefile" for more detailed information about Makefile Options.
Placing the drivers' source code in application/invered_pendulum/scr/drivers folder, C source and header file in the folder.
|imu.c/imu.h||get imu sensor data(int16_t raw data)|
|spi.c/spi.h||transfer qei data(int16_t) and pwm(int16_t)|
|timer.c/timer.h||Timer 1,2ms interrupt for motroTick|
The FastMath_Table is used to fast atan function, ranging in -0.98rad~0.45rad(table data is 1024 times of actual angle).The table index is equal to tangent value enlarges 128 times and add 192.
/* * n = m << 7 + 192, y = round(x << 10) * m: tangent value * n: array index * x: atan(m) * y: array[n] */
The Queue realizes queue functions through linear table, type:char or int.
QueueInit QueueClear QueueLength EnQueue DeQueue
Drawback: it implement queue by arrays, which will waste memory space and fix data type.
The TskDbg mainly uses for UART transmission.
|cmd.c/cmd.h||interact with user|
|dbgUart.c/dbgUart.h||uart transfer and uart Task|
The TskMotor completes data processing and algorithm application.
The file algorithm.s implements algorithms through assembly instructions.
The file assert.c is useful to handling exceptions.
The file physParmas.h contains macro define for data factor and customize typedef struct.