Ways to use MAVLink protocol

  1. Use the Standard dialect
    • Standard Dialect:here
    • If our requirement is satisfied with the Standard dialects only, we no need to generate the source file and no need to use mavgen tool.
    • One can directly use Prebuild libraries,here
    • For C: here
  2. Generate custom library file
    • If we have specific requirement which cannot be fulfilled by Stadard Dialect, need to generate custom library files.
    • Code generators create software libraries for specific programming languages from these XML message definitions.
    • These software libraries can then be used in the code.

Transmitting

  • Transmitting messages can be done by using the mavlink_msg_*_pack() function, where one is defined for every message.
  • Eg. mavlink_msg_gps_raw_int_pack
  • The packed message can then be serialized with mavlink_helpers.h:mavlink_msg_to_send_buffer()
  • Then writing the resultant byte array out over the appropriate serial interface.
  • Used header file: mavlink_msg_obstacle_distance.h
  • Primary variables
    • uint16_t distances[72]
    • uint8_t increment
    • uint8_t increment
    • float angle_offset

Testing MAVLink

  • Need to create a conda environment in the PC.
  • For that first need to install the miniconda in the PC from here.
  • Using above link, install miniconda for your operating system.
  • Run the downloaded exe.
  • Do not give installation path of miniconda which contains space(s). If your user name has space, try to give “C:\Users\Public\miniconda3” this king of path.
  • Open an anaconda prompt.
  • Create a virtual environment with installing Python version of your choice using command:
  • conda create -n environment_name python=3.10.4
  • Active an environment using:
  • conda activate environment_name
  • Now, cd into the open-source-autonomous-vehicle-controller folder.
  • Cd into the python folder.
  • Run below command:
  • pip install pymavlink
  • Then run python script
  • python mavcsv_logging.py
  • Now, go to Device Manager and under Ports (COM & LPT), See the port number in the next line.
  • In mavcsv_logging.py file, update the port number in mavutil.mavlink_connection() function.
  • You will get a below error:
  • PermissionError: [Errno 13] Permission denied: 'COM9'
  • Because COM9 port was being used by Tera Term.
  • Close the Tera term and try again running mavcsv_logging.py script.
  • You will get a csv file, namely logfile.csv.

Useful Resources


For more information refer documentation.