The NavQ onboard computer can be used for a variety of applications when used in conjunction with the NXP Hovergames drone. One of the best features is streaming video from the device to a computer running QGroundControl. This allows the drone to be monitored live while it is flying through QGroundControl.
But we need to run a script every time we want to initiate a pipeline to stream video from the device. This can be time consuming and inconvenient in the field. It would be much better if the NavQ would automatically start streaming video when it is in use.
We can use a tool called systemctl to do this for us. This is a scrip service that allows us to run a custom script when a condition is met. In our case, we want to run the GStreamer pipeline when the device is connected to the internet.
By automating this process, the NavQ will start streaming after it's plugged in, reducing time needed to set it up and increasing convenience when deployed. This guide will walk through automating this script.
PrerequisitesBefore we get started, please ensure that the NavQ device is connected to the internet and you have set it up as instructed in the GitBook. Please install PuTTY if you have not done so already, to allow us to SSH into the NavQ.
Extract the NavQ's IP address by running ifconfig -a
and connect to the address on port 22 using PuTTY (username and password are navq).
Start off by making a new directory /home/. cd into the directory and create a new file using sudo nano. The code is displayed below.
#!/bin/sh
sudo gst-launch-1.0 v4l2src ! video/x-raw,width=640,height=480,framerate=30/1 ! vpuenc_h264 bitrate=500 ! rtph264pay ! udpsink host=xxx.xxx.xxx.xxx port=5600 sync=false
Paste this command in the file and ensure to once again replace the xxx.xxx.xxx.xxx with your computer's IP address. Save the file and name it run-gstreamer.sh. Now we want to make the script executable, paste the following command in the terminal:
sudo chmod u+x run-gstreamer.sh
Great, now we want to integrate systemctl. Run the following command in the terminal:
sudo systemctl edit --force --full automate.service
A nano window will open prompting you to type. Copy and paste the following text into the terminal:
[Unit]
Description=My Script Service
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
WorkingDirectory=/pathtofolder
ExecStart=/pathtofolder/rungstreamer.sh
[Install]
WantedBy=multi-user.target
This is a unit file that tells the system what script to execute under which conditions.
Now save the file with the default name. Run the following to check the status of the script service:
sudo systemctl status automate.service
You should get a response similar to the one in the image above. Now we need to enable the service.
sudo systemctl enable automate.service
Now we want to see if the service functions. Start the service with the following command:
sudo systemctl start automate.service
This will force-start the service. Run the following again:
sudo systemctl status automate.service
You should get a printout similar to the one in the image above showing that the script service is active. You should get a video feed in QGroundControl. You can reboot the device now. The video feed should come in automatically.
sudo systemctl reboot
That's it! You're done!
Comments