{"id":18694491,"url":"https://github.com/luickk/dji_naza_interface_c-","last_synced_at":"2025-07-11T01:09:47.021Z","repository":{"id":122825107,"uuid":"137250932","full_name":"luickk/dji_naza_interface_c-","owner":"luickk","description":"A C++ interface for Raspberry to interact with DJI Naza V2 Flight controller","archived":false,"fork":false,"pushed_at":"2023-08-30T10:36:31.000Z","size":18170,"stargazers_count":15,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T07:11:35.220Z","etag":null,"topics":["autonomous-quadcoptor","cplusplus","dji","drone","naza","nazav2"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luickk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-13T17:47:38.000Z","updated_at":"2024-12-23T11:50:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"8eeb789b-aeaf-44a7-a8d4-e21d58516a93","html_url":"https://github.com/luickk/dji_naza_interface_c-","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luickk%2Fdji_naza_interface_c-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luickk%2Fdji_naza_interface_c-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luickk%2Fdji_naza_interface_c-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luickk%2Fdji_naza_interface_c-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luickk","download_url":"https://codeload.github.com/luickk/dji_naza_interface_c-/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248530576,"owners_count":21119600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autonomous-quadcoptor","cplusplus","dji","drone","naza","nazav2"],"created_at":"2024-11-07T11:10:59.778Z","updated_at":"2025-04-12T07:11:39.602Z","avatar_url":"https://github.com/luickk.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DJI Naza V2 C++ PWM Interface\n\nA C++ interface for the Raspberry Pi to interact with the DJI Naza V2 Flight controller. The project is a diy solution for people who don't have access to dji's libraries but still need the accuracy/ advantages of the Naza V2. It allows the user to control the Naza V2 via. a Raspberry by installing this library and write their own program using the methods supplied by the library. The library does that by emulating the PWM signals which actually/ normally come from a receiver to control the Naza V2(drone). To generate the PWM signal it uses the [PWM/Servo Driver - I2C interface - PCA9685](https://www.adafruit.com/product/815). The lib consists of two different section, **manual** and **autonomous**. **Manual** offers standard functions to control the drone, which are immediately executed. **Autonomous** provides functions which require a serial connection(to decode gps, gyro/ acc information) to the Naza V2 to fly for example to differnt waypoints(is highly experimental and partly unfinished, continued [here](https://github.com/cy8berpunk/ros_airdrop)).\n\n\nDemonstration video can be watched [here](media/demo.mp4)\n\n## Webinterface \n[The Webinterface](https://github.com/MrGrimod/dji_naza_web_interface) is built on top of this project and uses the tools/ binaries from this project to access the Naza. It's based on PHP and Js Ajax, the PHP scripts directly access the binaries compiled by this project and can be used to test the lib.\n\n## Pwm Reference\n\nThe Naza V2 can adapt to different controll interfaces PWM, PPM and S-Bus are possible. Here I will focus on PWM, since that is the one I chose to use. It is the simplest, most reliable and easiest to emulate.\n\nPWM input signal: \u003cbr\u003e\nHz: 50 \u003cbr\u003e\nPulse: 0.5-2.5 ms \u003cbr\u003e\n\nTo generate a proper signal you need to calculate the relative pulse length. For that you need two other values which represent the overall pulse period and the pulse length. The difference of both mustn't be greater than the period itself. The period is decomposed in 4096 values which is equivalent to a 12 Bit accuracy (2^12). So the difference of both of those values mustn't be greater than 4096. This relative pulse length can be calculated by multiplying the Hz rate, the period and the pulse length together.\n\n    50Hz:\n\n        50Hz* 0.0005s * 4096 = 102 (relative pulse length)\n\n        50Hz* 0.0025s * 4096 = 512 (relative pulse length)\n\nTo control the Naza V2 we need a relative pulse length that reaches from 102-512 (depends on calibration).\n\n\nSetup\n-------------------\n\n### Installation\n\n\u003e - `git clone https://github.com/MrGrimod/dji_naza_interface_c-.git` \u003cbr\u003e\nClone the project\n\n\n\u003e - `cd dji_naza_interface_c-`\u003cbr\u003e\n\n\u003e - `make`\u003cbr\u003e\nBuild the library's share object file.\n\n\n\u003e - `make install`\u003cbr\u003e\nInstall config and Headers to include dir  \n\n### Configuration \u0026 Calibration (required)\n\nTo make the library work you need to configure the library's config file (`/etc/naza/pwm_config.txt`) \u003cbr\u003e\nEach variable (left,middle,right) defines the transmitters throttle endpoint stick location. To find them you need to open your Naza Assistant and go to `Rc` section where you have to recalibrate the Naza for your transmitter. Next, start `examples/mod_pwm/` and find the fitting values for the throttle endpoints of left, right and \"middle\" value for each channel and add them to `pwm_config`.\n\n### Usage\n\nAfter successful installation you can include the header files `#include \"libnaza/naza_interface_manual.h\"` \u003cbr\u003e\nin your own project and link libnaza by using `-lnaza` and `-lwiringPi` flag.\n\n### Wiring\n\nConnect the PCA9685 over I2C with your raspberry pi and the Naza V2 input channels with the different output channels of the PCA9685.\n\n### Examples\n\n\u003e Usage:\n\u003e\n\u003e Build: `./reinstall` \u003cbr\u003e Start: `./\u003ctool\u003e`\n\n-  flight_sim \u003cbr\u003e\nCommand Line tool to test and debug the functionallity of basic functions of the project. \u003cbr\u003e\n\nCMD commands:\u003cbr\u003e\n*forward,back,throttle,left,right,tright,tleft,flm,neutral,arm*\u003cbr\u003e\n\n-  mod_pwm\u003cbr\u003e\nCommand Line tool to manually set relative PWM pulse lengths for certain channels\u003cbr\u003e\n\n-  recalibrate\u003cbr\u003e\nTool to calibrate the Naza V2. Start the calibration process in the Naza V2 Assistant Software, then start the recalibration tool and wait until it's done setting the endpoints for all channels.\u003cbr\u003e\n\n-  read gps\u003cbr\u003e\nTool to decode Serial GPS coming from the Naza GPS module. It inputs the data in a continuous stream of data.  \n\nDependencies\n-------------------\n\n\u003e - bcm2835 \u003cbr\u003e\n    `wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.49.tar.gz` \u003cbr\u003e\n    `tar xvfz bcm2835-1.49.tar.gz` \u003cbr\u003e\n    `cd bcm2835-1.49 `\u003cbr\u003e\n    `./configure `\u003cbr\u003e\n    `make `\u003cbr\u003e    \n    `sudo make install `\u003cbr\u003e\n\n\u003e - WiringPi\n\nSerial Communication with Naza GPS\n-------------------\n\n### Switching to AMA0 (old serial interface)\n\nThe BCM2837 on the Raspberry Pi3 , Pi3B+, PiZeroW has 2 UARTs (as did its predecessors), however to support the Bluetooth functionality the fully featured PL011 UART was moved from the header pins to the Bluetooth chip and the mini UART made available on header pins 8 \u0026 10.\n\nThis has a number of consequences for users of the serial interface.\n\nThe `/dev/ttyAMA0` previously used to access the UART now connects to Bluetooth.\nThe miniUART is now available on `/dev/ttyS0`.\nIn the latest operating system software there is a `/dev/serial0` which selects the appropriate device so you can replace `/dev/ttyAMA0` with `/dev/serial0` and use the same software on the Pi3 and earlier models.\n\nUnfortunately there are a number of other consequences:-\n\nThe mini UART is a secondary low throughput UART  \n  intended to be used as a console.\nThe mini Uart has the following features: \u003cbr\u003e\n• 7 or 8 bit operation. \u003cbr\u003e\n• 1 start and 1 stop bit. \u003cbr\u003e\n• No parities. \u003cbr\u003e\n• Break generation. \u003cbr\u003e\n• 8 symbols deep FIFOs for receive and transmit. \u003cbr\u003e\n• SW controlled RTS, SW readable CTS. \u003cbr\u003e\n• Auto flow control with programmable FIFO level. \u003cbr\u003e\n• 16550 like registers. \u003cbr\u003e\n• Baudrate derived from system clock. \u003cbr\u003e\nThere is no support for parity and the throughput is limited, but the latter should not affect most uses.\n\nThere is one killer feature \"Baudrate derived from system clock\" which makes the miniUART useless as the this clock can change dynamically e.g. if the system goes into reduced power or in low power mode.\u003cbr\u003e\n\nFor the GPS Data input stream we need a reliable and fast serial communication interface, so we need to disable miniUART and switch back to the old ttyAMA0 interface.\nTo do so follow these steps:\n\n1. To disable bluethooth and set `/dev/ttyAM0` to real UART (as before)\nEdit the file `/boot/config.txt` and add the following line at the end : \u003cbr\u003e\n\n    dtoverlay=pi3-disable-bt\n    1\n    dtoverlay=pi3-disable-bt\n\n2. Stop the bluetooth service with sudo systemctl disable hciuart and reboot. \u003cbr\u003e\n\n3. To switch bluetooth to software UART and set /dev/ttyAM0 to real UART (as before)\nKeep in mind that this one will remain possible software problem on bluetooth (software UART), but not on Serial (Hardware) \u003cbr\u003e\nEdit the file /boot/config.txt and add the following line at the end : \u003cbr\u003e\n\n    dtoverlay=pi3-miniuart-bt\n    core_freq=250\n    1\n    2\n    dtoverlay=pi3-miniuart-bt\n    core_freq=250\n\n4. Edit the file `/lib/systemd/system/hciuart.service` and replace  `/dev/ttyAMA0`  with  `/dev/ttyS0` \u003cbr\u003e\n\n5. If you have a system with udev rules that create `/dev/serial0`  and `/dev/serial1` (look if you have these one), and if so use `/dev/serial1` .\n\nThen reboot\n\n\n### Library functions\n\n#### Manual:\n\n- fly_throttle: \u003cbr\u003e\nSets the drone throttle for all motors. \u003cbr\u003e\n*Corresponds to channel T*\n\n- fly_forward: \u003cbr\u003e\nLets the drone fly forward \u003cbr\u003e\n*Corresponds to channel E*\n\n- fly_back: \u003cbr\u003e\nLets the drone fly backwards \u003cbr\u003e\n*Corresponds to channel E*\n\n- fly_left: \u003cbr\u003e\nLets the drone fly sideways left \u003cbr\u003e\n*Corresponds to channel A*\n\n- fly_right: \u003cbr\u003e\nLets the drone fly sideways right \u003cbr\u003e\n*Corresponds to channel A*\n\n- fly_turn_right: \u003cbr\u003e\nLets the drone turn right \u003cbr\u003e\n*Corresponds to channel R*\n\n- fly_turn_left: \u003cbr\u003e\nLets the drone turn left \u003cbr\u003e\n*Corresponds to channel R*\n\n- set_neutral: \u003cbr\u003e\nSets all stick positions to neutral.\n\n- recalibrate: \u003cbr\u003e\nMoves all sticks to throttle endpoints\n\n- set_flight_mode: \u003cbr\u003e\nSets the flight mode. You can select between: `gps, failsafe, selectable`\n*Corresponds to channel U*\n\n- arm_motors: \u003cbr\u003e\n**Arms the motors**\n\n#### Autonomous:\n\n- auto_liftoff \u003cbr\u003e\nLets the drone take off.\n\n- auto_landing \u003cbr\u003e\nLets the drone land.\n\n- fly_to_gps_pos \u003cbr\u003e\nLets the drone fly to a certain position.\n\n- turn_to_deg \u003cbr\u003e\nLets the drone fly turn to a certain position.\n\n- auto_hover \u003cbr\u003e\nLets the drone hover.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluickk%2Fdji_naza_interface_c-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluickk%2Fdji_naza_interface_c-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluickk%2Fdji_naza_interface_c-/lists"}