Showing posts with label PX4. Show all posts
Showing posts with label PX4. Show all posts

Wednesday, November 21, 2018

Start Gazebo and PX4 SITL separately

  • Terminal 1
make posix_sitl_default gazebo no_sim=1

  • Terminal 2
# PX4 gazebo plugins export GAZEBO_PLUGIN_PATH=${GAZEBO_PLUGIN_PATH}:/home/user/px4/Firmware/build/posix_sitl_default/build_gazebo export GAZEBO_MODEL_PATH=${GAZEBO_MODEL_PATH}:/home/user/px4/Firmware/Tools/sitl_gazebo/models # add iris model into warehouse world #run gazebo --verbose /home/user/px4/Firmware/Tools/sitl_gazebo/worlds/warehouse.world

Add iris into warehouse.world

<?xml version="1.0" ?> <sdf version="1.5"> <world name="default"> <!-- A global light source --> <include> <uri>model://sun</uri> </include> <!-- A ground plane --> <include> <uri>model://ground_plane</uri> </include> <include> <uri>model://asphalt_plane</uri> </include> <!--add iris model for example --> <include> <uri>model://iris</uri> <pose>1.01 0.98 0.83 0 0 1.14</pose> </include>

Note

Try to add model with gz command, the model add into the world model list but not visible

gz model --spawn-file=iris.sdf --model-name=iaaa -p 1.01 0.98 0.83 0 0 1.14

Friday, November 2, 2018

Hello DroneCode

The Dronecode SDK is a MAVLink Library for the PX4 flight stack, with APIs for C++ The library provides a simple API for managing one or more vehicles, providing programmatic access to vehicle information and telemetry, and control over missions, movement and other operations. SDK Main page

Install SDK

Note: First I Install from Release (deb) and try to compile the example takeoff_amd_land - The code look for action_result.h file that wasn't exists

Install SDK from source

git clone https://github.com/Dronecode/DronecodeSDK.git cd DronecodeSDK #master branch contain code like the deb git checkout develop git submodule update --init --recursive make default #Install sudo make default install sudo ldconfig # update linker cache

Takeoff example

Project struct

├── bin ├── build ├── CMakeLists.txt ├── docs ├── README.md └── src ├── CMakeLists.txt └── takeoff_and_land.cpp
  • root Cmake file
cmake_minimum_required(VERSION 2.8.12) project(xdrone) set(CMAKE_CXX_STANDARD 11) include_directories(/usr/local/include/dronecode_sdk) link_directories(/usr/local/lib) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) add_subdirectory(src)
  • src cmake file
add_executable(takeoff_and_land takeoff_and_land.cpp) target_link_libraries(takeoff_and_land dronecode_sdk dronecode_sdk_telemetry dronecode_sdk_action )

Paste code from takeoff_and_land

  • Run SITL make posix_sitl_default gazebo_iris from px4 Firmware folder
  • Run the code

Tuesday, September 4, 2018

PX4 SITL mavros and gazebo

Setup and run

  • Terminal 1 Setting environment
cd <Firmware_clone> make posix_sitl_default gazebo source Tools/setup_gazebo.bash $(pwd) $(pwd)/build/posix_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd) export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:$(pwd)/Tools/sitl_gazebo
  • Terminal 1 (launch gazebo and SITL)
roslaunch px4 posix_sitl.launch
  • Terminal 2 (launch mavros)
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"
  • Terminal 3 (mavros commands: call services)
rosservice call /mavros/set_mode "base_mode: 0 custom_mode: 'OFFBOARD'" rosservice call /mavros/cmd/arming "value: true" rosservice call /mavros/cmd/takeoff "{min_pitch: 0.0, yaw: 0.0, latitude: 0.0, longitude: 0.0, altitude: 10.0}"

Friday, August 17, 2018

PyMavlink and PX4 SITL

python implementation of the MAVLink protocol

  • Terminal 1: from PX4 Firmware run
make posix_sitl_default jmavsim

Tip: Run SITL without GUI , good performance save resource

source

  • Edit this file, which is part of jMAVSim repository, Visualizer3D.java13, and change setVisible(true) to setVisible(false).
# find . -name Visualizer3D.java vim `find . -name Visualizer3D.java` # search setVisible(true) //line 175 # change setVisible(true) to setVisible(false) # compile and run again make posix_sitl_default jmavsim

Now the SITL run without JMavsim GUI

| ___ \ \ \ / /   /   |
| |_/ /  \ V /   / /| |
|  __/   /   \  / /_| |
| |     / /^\ \ \___  |
\_|     \/   \/     |_/

px4 starting.

INFO  [Unknown] Calling startup script: bash etc/init.d-posix/rcS 0

INFO  [simulator] Waiting for initial data on UDP port 14560. Please start the flight simulator to proceed..
 
Init MAVLink
4000000 B/s on udp port 14556 remote port 14550

INFO  [mavlink] mode: Onboard, data rate: 4000000 B/s on udp port 14557 remote port 14540

  • use ipython/ python console
from pymavlink import mavutil master = mavutil.mavlink_connection("udp:127.0.0.1:14540") #master # <pymavlink.mavutil.mavudp at 0x7..> master.recv_match() _.to_dict() {'alt': 487971, 'hdg': 40, 'lat': 473977416, 'lon': 85455938, 'mavpackettype': 'GLOBAL_POSITION_INT', 'relative_alt': -12, 'time_boot_ms': 357265, 'vx': -3, 'vy': 0, 'vz': 0}

Thursday, August 9, 2018

PX4 SITL Dronekit

  • dependencies
  • run jmavsim as simulator
  • run dronekit sample code

Install dependencies

sudo apt-get install python-jinja2 sudo pip install numpy toml

Download PX4 and build

  • ROS and gazebo are preinstalled
  • mkdir px4 cd px4 git clone https://github.com/PX4/Firmware.git cd Framework wget https://raw.githubusercontent.com/PX4/Devguide/master/build_scripts/ubuntu_sim_common_deps.sh source ubuntu_sim_common_deps.sh #First Build (Using the jMAVSim Simulator) make posix jmavsim

    DroneKit

    dronekit
    • droneKit
    • dronekit-sitl
    sudo pip install dronekit

    Demo

    • Dronekit read data from PX4 SITL
    • Run PX4 SITL (simulation)

    dronekit sample code

    from dronekit import connect, VehicleMode connection_string = "127.0.0.1:14540" # Connect to the Vehicle. print("Connecting to vehicle on: %s" % (connection_string,)) vehicle = connect(connection_string, wait_ready=True) # Get some vehicle attributes (state) print " System status: %s" % vehicle.system_status.state

    Run gazebo simulation (without gzclient)

    HEADLESS=1 make posix_sitl_default gazebo