Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
curvin committed Nov 18, 2022
0 parents commit 8974e5b
Show file tree
Hide file tree
Showing 10 changed files with 848 additions and 0 deletions.
1 change: 1 addition & 0 deletions .catkin_workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file currently only serves to mark the location of a catkin workspace for tool integration
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.vscode
/build
/devel
127 changes: 127 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# PX4

## QGC地面站
``` shell
#Wifi数传通讯设置
MAV_1_CONFIG= TELEM_2 #设置TELEM_2为数传输出口
MAV_1_MODE = Onboard
SER_TEL2_BAUD = 921600 #设置波特率

#室内定点参数
EKF2_AID_MASK 24 #(不选择GPS,选择vision position fusion和vision yaw fusion)
EKF2_HGT_MODE Vision
MAV_ODOM_LP 1

#速度设置
MPC_XY_VEL_MAX 0.5
MPC_Z_VEL_MAX_DN 0.5
MPC_Z_VEL_MAX_UP 0.5

#PX4默认PID
MPC_XY_VEL_P_ACC 1.8
MPC_XY_VEL_I_ACC 0.6
MPC_XY_VEL_D_ACC 0.2

MPC_Z_VEL_P_ACC 4
MPC_Z_VEL_I_ACC 0.6
MPC_Z_VEL_D_ACC 0

MPC_XY_P 1.20
MPC_Z_P 1.20
```

## PX4 飞控稳定调试

- 首先在自稳模式下将PID参数调稳定,调试`Multicopter Rate Control`菜单下`MC_ROLLRATE_P``MC_ROLLRATE_I``MC_ROLLRATE_D`,`MC_PITCHRATE_P`,`MC_PITCHRATE_I`,`MC_PITCHRATE_D`这六个参数即可
- 自稳PID调试完成后,此时飞行会发现飞行器总是会朝某个方向“倾斜”飞行,此时最好先将机体各部位都固定稳定,中心最好在机体中心(电池位置最好也固定,不然电池的拆卸也是影响重心的一个要点)。然后调试`Sensors`菜单下的`SENS_BOARD_X_OFF``SENS_BOARD_Y_OFF`两个参数,最完美的状态是调试到roll和pitch不总是朝一个方向飞行,只会随机朝某个方向缓慢飞行
- 随后切换到offboard模式进行定位调试,如果设置指定高度后飞行器一直飞行不到指定高度,请增大`Multicopter Position Control`菜单下的`MPC_THR_HOVER``MPC_Z_P`参数
- - 随后调试定位的参数,`Multicopter Position Control`菜单下的`MPC_XY_P`,`MPC_XY_TRAJ_P`,`MPC_XY_VEL_D_ACC`,`MPC_XY_VEL_I_ACC`,`MPC_XY_VEL_P_ACC`这几个参数,注意增大其中`MPC_XY_VEL_I_ACC`参数对减小偏移有显著效果

## MAVESP8266

``` shell
#下载固件
https://firmware.ardupilot.org/Tools/MAVESP8266/latest/

#初始账户:ArduPilot
#初始密码:ardupilot

#连接上ESP8266后,打开192.168.4.1,连接实验室Wifi
```

# MAVROS

## 安装MAVROS
``` shell
sudo apt-get install ros-<ros_vision>-mavros ros-<ros_vision>-mavros-extras
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/
install_geographiclib_datasets.sh
sudo bash ./install_geographiclib_datasets.sh
#若wget失败,可直接下载sh文件运行
```

## MAVROS测试
``` shell
#连接Wifi数传到飞控
#查看Wifi数传IP地址

#设置mavros参数
roscd mavros/launch/
sudo vim px4.launch
#fcu_url udp://:[email protected]:12345 //33为数传地址
#gcs_url udp://:[email protected] //27为qgc主机地址(可以不设置)
#运行mavros
roslaunch mavros px4.launch

#运行rostopic,查看状态
rostopic echo /mavros/state
#注意,Wifi数传一次只能连接一个终端,连接mavros后就不能连接QGC地面站

#如果显示数据异常,修改以下信息
roscd mavros/launch
sudo vim px4_config.yaml
#将timesync_rate: 10.0 改为timesync_rate: 0.0
```

# 动捕设置

## 安装VRPN
``` shell
sudo apt-get install ros-<your ros vision>-vrpn*
```

## 运行VRPN
``` shell
roslaunch vrpn_client_ros sample.launch server:=192.168.31.128
#IP地址为动捕主机IP地址
```

# 实验平台操作

## 位置控制(无位姿)

``` shell
#完成上述操作,运行launch
roslaunch experiments system_init.launch

#新建终端
rostopic echo /mavros/state
#检查是否能切换到位置控制模式,可以切换则进行下一步操作

#打开position_control.cpp,将坐标点复制到poseArr数组
double poseArr[][3] = {
    {0, 0, hight_init}, //起飞
    {0, 0, hight_init}, //回到坐标原点
    //从这开始执行飞行任务
    {0, 0, 0.3},
    {0, 0, 0.3},
};

#重新编译ROS工作文件
catkin_make

#运行position_control节点
rosrun experiments position_control

#无人机自动解锁起飞,执行完任务后在任务终点悬停
```
69 changes: 69 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake

cmake_minimum_required(VERSION 3.0.2)

project(Project)

set(CATKIN_TOPLEVEL TRUE)

# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
RESULT_VARIABLE _res
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
# searching fot catkin resulted in an error
string(REPLACE ";" " " _cmd_str "${_cmd}")
message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()

# include catkin from workspace or via find_package()
if(_res EQUAL 0)
set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
# include all.cmake without add_subdirectory to let it operate in same scope
include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
add_subdirectory("${_out}")

else()
# use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
# or CMAKE_PREFIX_PATH from the environment
if(NOT DEFINED CMAKE_PREFIX_PATH)
if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
if(NOT WIN32)
string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
else()
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
endif()
endif()
endif()

# list of catkin workspaces
set(catkin_search_path "")
foreach(path ${CMAKE_PREFIX_PATH})
if(EXISTS "${path}/.catkin")
list(FIND catkin_search_path ${path} _index)
if(_index EQUAL -1)
list(APPEND catkin_search_path ${path})
endif()
endif()
endforeach()

# search for catkin in all workspaces
set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
find_package(catkin QUIET
NO_POLICY_SCOPE
PATHS ${catkin_search_path}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
unset(CATKIN_TOPLEVEL_FIND_PACKAGE)

if(NOT catkin_FOUND)
message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
endif()
endif()

catkin_workspace()
Loading

0 comments on commit 8974e5b

Please sign in to comment.