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}"

Monday, September 3, 2018

Pixhawk first connection

  • Connect to usb
  • Understand LED's
  • Write some dronekit code read heartbeat
  • Read GPS data with dronekit

Connect to USB

  • dmsg
[768651.390811] usb 3-2: Product: PX4 FMU v2.x [768651.390814] usb 3-2: Manufacturer: 3D Robotics [768651.390816] usb 3-2: SerialNumber: 0 [768651.391528] cdc_acm 3-2:1.0: ttyACM0: USB ACM device

LED's

  • Flashing blue: Disarmed, no GPS lock found
  • Flashing green: Disarmed (ready to arm), GPS lock acquired.
  • Full list: http://ardupilot.org/plane/docs/common-leds-pixhawk.html

Connect GPS and Compass

  • LED go to blinking green
  • my GPS led blink with green led's

Dronekit hello

#!/usr/bin/env python from dronekit import connect, VehicleMode connection_string = "/dev/ttyACM0" # 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 "Get some vehicle attribute values:" print " GPS: %s" % vehicle.gps_0 print " Battery: %s" % vehicle.battery print " Last Heartbeat: %s" % vehicle.last_heartbeat print " Is Armable?: %s" % vehicle.is_armable print " System status: %s" % vehicle.system_status.state print " Mode: %s" % vehicle.mode.name # settable # Close vehicle object before exiting script vehicle.close()

Read GPS data

#!/usr/bin/env python from dronekit import connect, VehicleMode import time connection_string = "/dev/ttyACM0" def log_gps(self, name, msg): print msg # Connect to the Vehicle. print("Connecting to vehicle on: %s" % (connection_string,)) vehicle = connect(connection_string, wait_ready=True) #vehicle.add_message_listener('GLOBAL_POSITION_INT', log_gps) vehicle.add_message_listener('GPS_RAW_INT', log_gps) time.sleep(5) vehicle.close()

Result

  • GPS_RAW_INT: The global position, as returned by the Global Positioning System (GPS). This is NOT the global position estimate of the sytem, but rather a RAW sensor value. See message GLOBAL_POSITION for the global position estimate. Coordinate frame is right-handed, Z-axis up (GPS frame)
GPS_RAW_INT {time_usec : 4246687000, fix_type : 4, lat : 324283000, lon : 350107200, alt : 45700, eph : 98, epv : 171, vel : 14, cog : 23071, satellites_visible : 8}
  • GLOBAL_POSITION_INT: fused GPS and accelerometers). The position is in GPS-frame (right-handed, Z-up)
GLOBAL_POSITION_INT {time_boot_ms : 2848710, lat : 324284000, lon : 350107830, alt : 99400, relative_alt : 8000, vx : -17, vy : 9, vz : 8, hdg : 4893}

Reference

Sunday, September 2, 2018

Ardupilot and MAVROS

Install MAVROS

sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras
  • GCS — Ground Control Station
  • FCU — Flight Control Unit (pixhawk)
  • OBC — OnBoard Computer (your odroid or raspberry)

Run SITL and ROS

Terminal 1 (sitl)

sim_vehicle.py -v ArduCopter --console

Terminal 2 (launch)

udp://[bind_host][:port]@[remote_host[:port]][/?ids=sysid,compid] roslaunch mavros apm.launch fcu_url:=udp://127.0.0.1:14551@14555

rqt (Terminal 3)

Use GUI to control (call service, monitor and pub topics)

rqt
  • plugins -> robots tools -> runtime monitor

Set mode

  • plugins -> Services -> Service Caller
  • from service combo select /mavros/set_mode

Reference

Mission Planner VirtualBOX Dronekit-sitl

MissionPlaner on virtualbox

Mission Planer setup

  • Host: ubuntu 16.04
  • Guest: Windows7
  • Virtualbox
  • Install VM VirtualBox Extension Pack (support USB2,3)
  • Install VB Guest Addition
  • Install Firfox (IE crash all the time)
  • .Net 4.62
  • Mission Planner
  • Set VBOX network in bridge mode

Demo: Using Dronekit and Dronekit-SITL

sudo pip install mavproxy sudo pip install dronekit sudo pip install dronekit-sitl
  • Terminal 1
dronekit-sitl copter
  • Terminal 2
export MP_IP="192.168.2.117" mavproxy.py --master tcp:127.0.0.1:5760 --out udp:127.0.0.1:14551 --out udp:`echo $MP_IP`:14550
  • Virtualbox (windows)
    • Change the connection type combo to udp
    • Select port 14550

Note

When run mavproxy got an error: AttributeError: 'module' object has no attribute 'MAV_TYPE_DODECAROTOR'

After some search in google , I found that pymavlink need to upgraded , download and install from pypi.org version 2.2.10 (current version 2.0.6)

Friday, August 31, 2018

Setting Title for Tab in Terminator


  • Add code to ~/.bashrc
  • Run source ~/.bashrc
  • Usage: set_title <Title>

  • source

    set_title() {
    ORIG=$PS1
    TITLE="\e]2;$*\a"
    PS1=${ORIG}${TITLE}
    }


    Reference 

    Tuesday, August 28, 2018

    ROS LIVE_CLASS

    Start to follow and implement LIVE CLASS from "The Construct"
    are a greate and funny guide

    #13:ROS Navigation Stack How To

    In this ROS LIVE-Class Ricardo show how to
    making a differential drive robot create a map (SLAM), localize on that map (robot localization), and then navigate on the environment using the map (path planning and obstacle avoidance).

    #14: How To Control Robot Joints With ROS

    In this ROS LIVE-Class Ricardo show how to add ROS control to a joint in a simulated robot

    #19: Let’s Use Gazebo Plugins

    In this ROS LIVE-Class Ricardo show how to create a Gazebo plugin for a robot simulated world. The plugin will allow us to connect/disconnect the light of the world by means of a ROS topic .

    Friday, August 24, 2018

    NodeMCU AT commands

    Firmware's

    ESP 8266 has few firmware options

    • AT+command (default)
    • NodeMCU
    • Custom Firmware (using the Arduino IDE)

    In this tutorial we will flash AT FW with esptool and use Arduino Serial monitor to send AT commands

    Connect NodeMCU and use Arduino serial monitor to send AT commands

    • Flash AT firmware
    • Connect with arduino
    • from arduino serial monitor send commands

    Connect device to usb port

    Note: in linux no additional driver need to be install, CP2102 is recognized without the need for installing drivers

    • dmesg output
    usbserial: USB Serial support registered for cp210x cp210x 3-1:1.0: cp210x converter detected usb 3-1: cp210x converter now attached to ttyUSB0

    Flush default firmware (AT support)

    • download default FW FW location
    • download flashing tool (esptool)

    run esptool to flash FW

    python esptool.py --port /dev/ttyUSB0 write_flash 0x00000 ~/Downloads/v1111ATFirmware.bin

    Usag and run.

    • Use Arduino IDE

    • Config arduino serial monitor

      • set baud rate: 115200
      • set Both NL & CR
    • Run AT commands(AT+)

    AT OK AT+GMR AT version:0.25.0.0(Jun 5 2015 16:27:16) SDK version:1.1.1 Ai-Thinker Technology Co. Ltd. Jun 23 2015 23:23:50 OK

    Reference