This is a simple MAVLink to UART interface example for Unix systems that can allow communication between Gremsy's Gimbal and an Onboard computer.
This will provide examples of controlling and communicating with Gremsy's Gimbal.
In order to compile you need the following packages:
CMake version 3.5 or higher
G++ compiler or Clang compiler
C and C++ standard libraries
$ cd gSDK/
$ mkdir build && cd build
$ cmake ..
$ make
Connect the COM2 cable to your Onboard Computer.
The hardware connection between an GIMBAL and a PC or Linux machine. Note that:
The recommended choice of USB to TTL cable is FT232 module.
Refer to: gSDK Documentation
An FTDI cable will show up on a ttyUSB*
.
Run the example executable on the host shell:
You have to pick a port name, try searching for it with
$ ls /dev/ttyACM*
$ ls /dev/ttyUSB*
Run the example executable on the host shell:
$ cd gSDK/
$ ./gSDK -d /dev/ttyUSB0
To stop the program, use the key sequence Ctrl-C
.
Here's an example output:
OPEN PORT
Connected to /dev/ttyUSB0 with 115200 baud, 8 data bits, no parity, 1 stop bit (8N1)
START WRITE THREAD
Lost Connection!
Lost Connection!
START READ THREAD
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Lost Connection!
Found GIMBAL [SysID][CompID]: [1][154]
GOT [VERSION_X] 7
GOT [STIFF_TILT] 20
GOT [STIFF_ROLL] 70
GOT [STIFF_PAN] 60
GOT [FILTER_OUT] 1
GOT [PWR_TILT] 20
GOT [PWR_ROLL] 70
GOT [PWR_PAN] 60
GOT [FLW_LPF_TILT] 20
GOT [FLW_LPF_PAN] 20
GOT [RC_TYPE] 15
GOT [GYRO_LPF] 4
GOT [RC_LIM_MIN_TILT] -45
GOT [RC_LIM_MAX_TILT] 45
GOT [RC_LIM_MIN_ROLL] -40
GOT [RC_LIM_MAX_ROLL] 40
GOT [RC_LPF_TILT] 80
GOT [RC_LPF_ROLL] 80
GOT [RC_LPF_PAN] 80
GOT [FLW_WD_TILT] 5
GOT [FLW_WD_PAN] 20
GOT [RC_SPD_TILT] 30
GOT [RC_SPD_ROLL] 30
GOT [RC_SPD_PAN] 30
GOT [RC_REVERSE_AXIS] 24
GOT [VERSION_Y] 7
GOT [VERSION_Z] 3
GOT [RC_LIM_MIN_PAN] -320
GOT [RC_LIM_MAX_PAN] 320
GOT [MAV_TS_ENCNT] 1
Check [VERSION_X] 7
Check [VERSION_Y] 7
Check [VERSION_Z] 3
Check [STIFF_TILT] 20
Check [STIFF_ROLL] 70
Check [STIFF_PAN] 60
Check [PWR_TILT] 20
Check [PWR_ROLL] 70
Check [PWR_PAN] 60
Check [FILTER_OUT] 1
Check [GYRO_LPF] 4
Check [FLW_LPF_TILT] 20
Check [FLW_LPF_PAN] 20
Check [FLW_WD_TILT] 5
Check [FLW_WD_PAN] 20
Check [RC_SPD_TILT] 30
Check [RC_SPD_ROLL] 30
Check [RC_SPD_PAN] 30
Check [RC_LPF_TILT] 80
Check [RC_LPF_ROLL] 80
Check [RC_LPF_PAN] 80
Check [RC_REVERSE_AXIS] 24
Check [MAV_TS_ENCNT] 1
Check [RC_LIM_MIN_TILT] -45
Check [RC_LIM_MAX_TILT] 45
Check [RC_LIM_MIN_ROLL] -40
Check [RC_LIM_MAX_ROLL] 40
Check [RC_LIM_MIN_PAN] -320
Check [RC_LIM_MAX_PAN] 320
Check [RC_TYPE] 15
Use mavlink gimbal V1
Gimbal Firmware version is 7.8.3.OFFICIAL
Set gimbal send raw encoder value.
GET GIMBAL DEVICE:
Vendor name: GREMSY
Model name: MIO
Request gimbal device information.
Please Enter y/n(yes or no) to setting gimbal mavlink message rate
n
Please Enter y/n(yes or no) to setting gimbal stiffness - follow param
n
Please Enter number to select type of gimbal
1. Two axis
2. Three axis
2
Please Enter number to select three axis gimbal mode
1. Normal mode
2. Inverted mode
1
You selected gimbal mount mode
Three axis Normal Mount
Please Enter number [0-15] to seclect Gimbal control mode
0. OFF Gimbal
1. ON Gimbal
2. Change mount mode
3. Gimbal information
4. Config gimbal follow parameter
5. Set Gimbal to LOCK mode
6. Set Gimbal to move angle in LOCK mode
7. Set Gimbal to move rate in LOCK mode
8. Set Gimbal to FOLLOW mode
9. Set Gimbal to move angle in FOLLOW mode
10. Set Gimbal to move rate in FOLLOW mode
11. Set Gimbal to MAPPING mode
12. Set Gimbal to Return Home
13. Set Gimbal Reboot
14. Upgrade Firmware
15. Monitoring Encoder - Attitude - IMU
^C
TERMINATING AT USER REQUEST
CLOSE THREADS
CLOSE PORT
GOT [PARAMETER] [VALUE]: Lists the retrieved gimbal parameters and their respective values. These parameters include stiffness, power, filter settings, RC limits, and other configuration values.
Example parameters:
VERSION_X
, VERSION_Y
, VERSION_Z
STIFF_TILT
, STIFF_ROLL
, STIFF_PAN
PWR_TILT
, PWR_ROLL
, PWR_PAN
FLW_LPF_TILT
, FLW_LPF_PAN
RC_TYPE
GYRO_LPF
RC_LIM_MIN_TILT
, RC_LIM_MAX_TILT
, etc.
Check [PARAMETER] [VALUE]: Confirms that the retrieved parameters match the expected values.
Please Enter y/n(yes or no) to setting gimbal mavlink message rate: Prompts the user to confirm whether to set gimbal messages rate.
Please Enter y/n (yes or no) to setting gimbal stiffness - follow param: Prompts the user to confirm whether to set gimbal stiffness and follow parameters.
Please Enter number to select type of gimbal: Prompts the user to select the gimbal type.
1. Two axis
2. Three axis
Please Enter number to select two axis gimbal mount mode: Prompts the user to select the mount mode for a two-axis gimbal.
1. Two axis
is selected, additional prompts will appear:1. Roll-Tilt Mount
2. Pan-Tilt Mount
2. Three axis
is selected, additional prompts will appear:1. Normal mode
2. Inverted mode
Please Enter number [0-15] to select Gimbal control mode: Prompts the user to select the desired gimbal control mode.
0. OFF Gimbal
1. ON Gimbal
2. Change mount mode
3. Gimbal information
4. Config gimbal follow parameter
5. Set Gimbal to LOCK mode
6. Set Gimbal to move angle in LOCK mode
7. Set Gimbal to move rate in LOCK mode
8. Set Gimbal to FOLLOW mode
9. Set Gimbal to move angle in FOLLOW mode
10. Set Gimbal to move rate in FOLLOW mode
11. Set Gimbal to MAPPING mode
12. Set Gimbal to Return Home
13. Set Gimbal Reboot
14. Upgrade Firmware
15. Monitoring Encoder - Attitude - IMU
Turns off the gimbal.
Turns on the gimbal.
Similar to 5. Gimbal Configuration Prompts, this option allows the user to change the mount mode of the gimbal. The prompts for changing the mount mode are as follows:
1. Two axis
2. Three axis
1. Two axis
is selected, additional prompts will appear:1. Roll-Tilt Mount
2. Pan-Tilt Mount
1. Three axis
is selected, additional prompts will appear:1. Normal mode
2. Inverted mode
Displays information about the gimbal.
For example:
Gimbal Firmware version is 7.7.3.OFFICIAL
You selected gimbal mount mode
Two axis Roll-Tilt mount
Gimbal mode: 2
Gimbal state: 2
Raw imu: xacc:200, yacc:-218, zacc:8174, xgyro:8, xgyro:-8, xgyro:-36(raw)
Gimbal attitude Pitch - Roll - Yaw: 0.00 - -0.00 - -0.01
Gimbal encoder Pitch - Roll - Yaw: 0.00 - -0.00 - -0.01
Config follow TILT: Dir: 0 -- Speed control: 30 -- Smooth control: 80 -- Smooth follow: 20 -- Window follow: 5
Config follow ROLL: Dir: 0 -- Speed control: 30 -- Smooth control: 80 -- Smooth follow: 0 -- Window follow: 0
Config follow PAN: Dir: 0 -- Speed control: 30 -- Smooth control: 80 -- Smooth follow: 20 -- Window follow: 20
Pitch max: 45 -- Pitch min: -45
Roll max: 40 -- Roll min: -40
Yaw max: 320 -- Yaw min: -320
Tilt hold strength: 20 -- Tilt stiffness: 20
Roll hold strength: 70 -- Roll stiffness: 70
Pan hold strength: 60 -- Pan stiffness: 60
Gyro filter: 4
Output filter: 1
Allows the user to configure the follow parameters for the gimbal.
Chose axis: Prompts the user to select the axis for which they want to configure the follow parameters.
1: Tilt
2: Roll
3: Pan
4: Reset parameter
Other: Exit
Example Process:
1
(Tilt)0
180
50
10
10
After inputting the parameters, the system will display the configured settings:
Config TILT: Dir: 0 -- Speed control: 180 -- Smooth control: 50 -- Smooth follow: 10 -- Window follow: 10
The user is then prompted to continue or not.
y
to continue or n
to exit.If the user chooses to reset parameters:
4
(Reset parameter)Sets the gimbal to LOCK mode, where the gimbal maintains its current orientation regardless of the movement of the base.
Allows the user to set a specific angle for the gimbal to move to while in LOCK mode.
Sets the gimbal to LOCK mode and moves it to a specified angle.
Note that this function utilizes the coordinate system [-180, 180].
In LOCK mode, this option allows the user to set the gimbal's movement rate.
Sets the gimbal to FOLLOW mode, where the gimbal follows the movement of the attached device.
In FOLLOW mode, this option allows the user to set the gimbal to a specific angle.
Sets the gimbal to FOLLOW mode and moves it to a specified angle.
Note that this function utilizes the coordinate system [-180, 180].
In FOLLOW mode, this option allows the user to set the gimbal's movement rate.
Sets the gimbal to MAPPING mode, which may be used for specific applications such as 3D mapping or scanning.
Sets the gimbal to return to its home position.
Reboots the gimbal. Please note that it takes about 10 seconds to reboot successfully.
Upgrade the gimbal firmware using a local hex file.
Enter the path of the firmware file.
Example:
Enter a path: /home/Gremsy/User/gSDK/FW/gremsyMio-2Axis_v783_Official.hex
The path: /home/Gremsy/User/gSDK/FW/gremsyMio-2Axis_v783_Official.hex
CLOSE THREADS
CLOSE PORT
OPEN PORT
Connected to /dev/ttyUSB0 with 460800 baud, 8 data bits, even parity, 1 stop bit (8N1)
Entering bootloader mode...
[✓] Parse Hex File
[✓] Connecting
[✓] Get CMD
[✓] Get ID
[✓] Erase memory
[==================================================] 100% Flash memory
Code flashed successfully!
Note: If the upgrade is interrupted and gSDK cannot reconnect, you can use the upgrade_gimbal example for upgrading.
Monitoring Encoder - Attitude - IMU
Example:
Duration (in seconds):
2
Raw imu: xacc:234, yacc:-12, zacc:8034, xgyro:-32, xgyro:-21, xgyro:-35(raw)
Gimbal attitude Pitch - Roll - Yaw: (0.40) - (-0.30) - (0.00)
Gimbal encoder Pitch - Roll - Yaw: (-23336) - (-216) - (0)
Raw imu: xacc:-851, yacc:-15, zacc:8014, xgyro:-70, xgyro:1019, xgyro:-5(raw)
Gimbal attitude Pitch - Roll - Yaw: (0.56) - (6.29) - (-0.00)
Gimbal encoder Pitch - Roll - Yaw: (-23348) - (1024) - (0)
Raw imu: xacc:-2342, yacc:-20, zacc:7639, xgyro:-60, xgyro:323, xgyro:-37(raw)
Gimbal attitude Pitch - Roll - Yaw: (0.28) - (18.23) - (-0.00)
Gimbal encoder Pitch - Roll - Yaw: (-23276) - (3252) - (0)
Raw imu: xacc:-3069, yacc:-37, zacc:7401, xgyro:-34, xgyro:55, xgyro:-34(raw)
Gimbal attitude Pitch - Roll - Yaw: (0.32) - (23.68) - (0.00)
Gimbal encoder Pitch - Roll - Yaw: (-23268) - (4276) - (0)
TERMINATING AT USER REQUEST: Indicates that the user has requested to terminate the program.
CLOSE THREADS: Closes the read and write threads.
CLOSE PORT: Closes the port connection.
Follow the prompts to configure and control the gimbal. Input the required values as instructed by each prompt. This menu system is designed to facilitate easy interaction with the gimbal for setup and operation.
For further assistance, please contact support at [support@gremsy.com].