Tuesday, October 2, 2018

RPi MAVROS Pixhawk connection

rpi_mcu_1.md

RPi 3+ Setup

Image

  • Download preinstall ROS and OpenCV on Raspbian from ROSbots
  • Install (Etcher)[https://etcher.io/] Flash OS images to SD cards & USB drives, safely and easily
  • Flash the image

Enabled ssh

  • In the boot partition
  • Paste empty file named ssh

Enabled wireless

  • In the rootfs partition goto /etc/wpa_supplicant
cd <rootfs>/etc/wpa_supplicant sudo vim wpa_supplicant.conf
  • Paste and edit at the end of the file
network={ ssid="The_ESSID_from_earlier" psk="Your_wifi_password" }

First boot

  • Connect with ssh
    • user:pi password:rosbots!

Pi config

  • change locals
  • changed password
  • changed rootfs partition size
sudo raspi-config

Resize swap file

sudo vim /etc/dphys-swapfile # update CONF_SWAPSIZE=1024 # save and exit sudo /etc/init.d/dphys-swapfile stop sudo /etc/init.d/dphys-swapfile start #check free -m

Install mavlink & mavros from source

Use wstool utility for retrieve source Use catkin tool for build

sudo apt-get install python-catkin-tools python-rosinstall-generator
sudo apt-get install libgeographic-dev sudo apt-get install geographiclib-tools sudo apt install python-future
  • Create catkin workspace
mkdir - p ~/catkin_ws/src cd catkin_ws catkin init
  • Crate MAVLink and MAVROS install instruction
# Mavlink rosinstall_generator --rosdistro kinetic mavlink | tee /tmp/mavros.rosinstall #MAVROS rosinstall_generator --upstream mavros | tee -a /tmp/mavros.rosinstall
wstool merge -t src /tmp/mavros.rosinstall wstool update -t src -j4 rosdep install --from-paths src --ignore-src -y
  • Got Error
ERROR: the following packages/stacks could not have their rosdep keys resolved to system dependencies: mavros: No definition of [geographic_msgs] for OS [debian] mavros_extras: No definition of [tf] for OS [debian] test_mavros: No definition of [control_toolbox] for OS [debian] mavros_msgs: No definition of [geographic_msgs] for OS [debian]
  • Install dependencies (run rosinstall_generator for each of the packages)
  • Todo: dependency resolve ?
rosinstall_generator --rosdistro kinetic $XXX | tee -a /tmp/mavros.rosinstall geographic_msgs uuid_msgs nav_msgs tf control_toolbox actionlib_msgs realtime_tools diagnostic_msgs urdf eigen_conversions tf2_ros dynamic_reconfigure tf2_eigen rosconsole_bridge orocos_kdl visualization_msgs angles tf2_py tf2 tf2_msgs urdf_parser_plugin diagnostic_updater control_msgs trajectory_msgs actionlib rosbag_migration_rule
  • Run again
wstool merge -t src /tmp/mavros.rosinstall wstool update -t src -j4 rosdep install --from-paths src --ignore-src -y
  • Build
catkin build
  • todo: Installer script
files=() for file_name in files do rosinstall_generator --rosdistro kinetic $file_name | tee -a /tmp/mavros.rosinstall done

Mavros_extra compile error

tf2_eigen/tf2_eigen.h: No such file or directory #include <tf2_eigen/tf2_eigen.h>
  • check if tf2_eigen compile
Starting >>> tf2_eigen Starting >>> tf2_py Finished <<< mavros_msgs [ 11.3 seconds ] Finished <<< tf2_eigen [ 0.9 seconds ]
  • Add tf2_eigen to find_package (CMakeLists.txt)
find_package(catkin REQUIRED COMPONENTS mavros roscpp mavros_msgs sensor_msgs geometry_msgs std_msgs visualization_msgs urdf tf tf2_eigen )

install GeographicLib

- Download from git `install_geographiclib_dataset.sh` - Run it

Connect with USB

  • Connect pixhawk usb to RPI usb
  • Use default fcu_url "/dev/ttyACM0:57600"
  • Note Don't forget to source (add to .bashrc)
  • From RPi run roslaunch mavros apm.launch
  • Run diagnostic
rostopic echo -n1 /diagnostics level: 0 name: "mavros: Heartbeat" message: "Normal" hardware_id: "/dev/ttyACM0:57600" values: - key: "Heartbeats since startup" value: "10" - key: "Frequency (Hz)" value: "0.948061" - key: "Vehicle type" value: "Quadrotor" - key: "Autopilot type" value: "ArduPilotMega / ArduCopter" - key: "Mode" value: "GUIDED" - key: "System status" value: "Standby"
  • Note: if No GPS data
name: "mavros: GPS" message: "3D fix" hardware_id: "/dev/ttyACM0:57600" values: - key: "Satellites visible" value: "0"
  • Run rosrun mavros mavsys rate --all 10 (need configure stream rate parameters.)

Todo: connect Serial

No comments: