Wednesday, August 22, 2018

Pymavlink Ardupilot SITL

  • ardupilot SITL

  • pamavlink

  • Terminal 1

sim_vehicle.py --console
  • Terminal 2 (python code)
from pymavlink import mavutil master = mavutil.mavlink_connection('tcp:127.0.0.1:5762') # Get some information ! while True: try: print(master.recv_match().to_dict()) except: pass

  • Terminal 3 (netstat -natp)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:5760 0.0.0.0:* LISTEN 5976/arducopter tcp 0 0 0.0.0.0:5762 0.0.0.0:* LISTEN 5976/arducopter tcp 0 0 0.0.0.0:5763 0.0.0.0:* LISTEN 5976/arducopter

python output

{'mavpackettype': 'TIMESYNC', 'ts1': 1854891080001, 'tc1': 0} {'custom_mode': 0, 'system_status': 3, 'base_mode': 81, 'autopilot': 3, 'mavpackettype': 'HEARTBEAT', 'type': 2, 'mavlink_version': 3} {'custom_mode': 0, 'system_status': 3, 'base_mode': 81, 'autopilot': 3, 'mavpackettype': 'HEARTBEAT', 'type': 2, 'mavlink_version': 3} {'custom_mode': 0, 'system_status': 3, 'base_mode': 81, 'autopilot': 3, 'mavpackettype': 'HEARTBEAT', 'type': 2, 'mavlink_version': 3}

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

    Wednesday, August 8, 2018

    Programing NodeMcu with Arduino IDE


    1. setup additional board url
    2. install board manage
    3. set board and port
    4. select blink example
    5. upload and run

    Setup additional board url

    file -> preference paste the link into field "Additional Bard Manager URL"



    http://arduino.esp8266.com/stable/package_esp8266com_index.json

    Install board

    Tools -> Board -> Board manager
    filter: esp8266

    Set board and port

    board: NodeMcu 1.0
    port: /dev/USB0

    Select blink example

    File -> Example -> esp8266 -> blink

    Upload and run

    void setup() {
      pinMode(LED_BUILTIN, OUTPUT);
    }

    void loop() {
      digitalWrite(LED_BUILTIN, LOW);
      delay(1000);
      digitalWrite(LED_BUILTIN, HIGH);
      delay(2000);
    }

    GO lang on Ubuntu 16.04

    Downloading and installing Go 1.9.1, Setup environment, building a simple Hello World application

    Download and setup

    curl -O https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz
    tar -xvf go1.9.1.linux-amd64.tar.gz
    sudo mv go /usr/local 

    Setting path

    vim ~./profile
    #add as last line
    export PATH=$PATH:/usr/local/go/bin

    Init

    source ~/.profile

    Test

    mkdir $HOME/gowork
    mkdir -p $HOME/gowork/src/hello

    Set gopath

    export GOPATH=$HOME/gowork

    Write hello.go

    Note: save under $HOME/gowork/src/hello

    package main
    import "fmt"
    func main() {
         fmt.Printf("hello, world\n")
    }

    Compile and run 

    use run, compile or install
    from source folder run
    go run hello.go
    #or
    go build hello.go
    ./hello

    cd $GOPATH
    go install hello
    #run
    $GOPATH/bin/hello

    Install and config Go extension on VSCode

    This extension uses a set of Go tools to provide the various rich features. These tools are installed in your GOPATH by default

    settings

    "go.gopath": "/home/user/gowork"

     

     

    Reference

    Install Go 1.9.1 on Ubuntu 16.04

    Tuesday, August 7, 2018

    Hello Arduino and FIRMATA

    Firmata is a protocol for communicating with microcontrollers from software on a computer
    Like Arduino for example :
    In essence it turns your Arduino device into a slave with a simple provided sketch. Then using the python/or any other language you can interface the Arduino via Serial bus and exposed API provided by the Firmata system

    1. Install arduino IDE
    2. Add dialup group to user `sudo adduser $USER dialout
    3. Upload Firmata to arduino
      1. File -> Examples -> Firmata -> StandardFirmata
    4. Install python library
      1.  sudo pip install pyfirmata
    5. Write some code

    code example to turn on output 13 (build-in led)

    from pyfirmata import Arduino, util
    board = Arduino('/dev/ttyACM0')
    board.digital[13].write(1)

    Reference

    Sunday, August 5, 2018

    VSCode tips for ROS

    Tip1 - Adding a file extension to a language

    You can add new file extensions to an existing language with the files.associations setting, for example assign gazebo .world file to XML

    "files.associations":{
     ".world": "xml"
    }


    Tip2 - use code runner to check urdf files

    code runner:  Run code snippet or code file for multiple languages
    • install 'Code runner' extension into vscode 
    • install check_urdf (apt-get install liburdfdom-tools)
    • from settings append file extension into code runner mapping
    "code-runner.executorMapByFileExtension": { 
    ".urdf": "check_urdf"

    Tip3 - use code runner to check xacro files

    ROS node xacro in package xacro convert xacro  file to urdf

    rosrun xacro xacro <file_name.xacro>

    The idea is to run the above command redirect the output to tmp file and then run check_urdf on it.

    "files.associations":{
    ".xacro": "rosrun xacro xacro --inorder $fullFileName > /tmp/tmp.urdf && check_urdf /tmp/tmp.urdf"
    }


    code runner supported parameters
    • $workspaceRoot: The path of the folder opened in VS Code
    • $dir: The directory of the code file being run
    • $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
    • $fullFileName: The full name of the code file being run
    • $fileName: The base name of the code file being run, that is the file without the directory
    • $fileNameWithoutExt: The base name of the code file being run without its extension