We did some more formal testing of the servos to identify the time delay. We set up an LED on the Pi to signal the time the servo PWM signal is sent on the Pi, and then did slow motion videos to observe the servo response. The JX PDI-6221MG-120 is really slow and not terribly precise. We ordered the KST BLS815 V8 servos and reran the tests and found them to be much faster and more precise.
We ran a ramp test. We sent a series of servo commands ramping from 0 degrees up to 20 degrees then back down to -20 degrees and up to 0 degrees. This was repeated for a series of cycles. The commands were sent at 50Hz with each command being for a 4 degree change. The Pi turns the LED on when it begins sending the upward trajectory and turns the LED off when it starts sending the downward commands.
| Servo | time to movement | ramp lag | ramp degree |
|---|---|---|---|
| JX PDI-6221MG-120 | 33 ms | 80 ms | 10 |
| KST BLS815 V8 | 30 ms | 33 ms | 20 |
Both servos had about the same amount of time between when the first message was sent and when the gimbal started moving. This was about 30 ms. As the ramp continued, the JX PDI-6221MG-120 developed a constant 80 ms lag and failed to reach the required 20 degrees before changing direction. It stopped at around 10 degrees. The KST BLS815 V8 developed a constant lag of 33 ms and always reached the full 20 degrees of rotation before changing direction.
You can see from our test flight that although the drone balances, it oscillates around a balance point. We don't have the precise control that we need. We were able to identify a time delay in the servos by looking at the flight data and comparing it with the expected behavior based on the equations of motion. We've confirmed that the delay comes mostly from actuation of the servos. We had to make a slow motion video of the gimbals responding to commands from the Pi with an LED that lights when the first message is sent. There's about a 30ms delay between when the Pi sends the message and when the servos start to move. The servos then get further behind leading to about a 120 ms delay. The servos we used were JX PDI-6221MG-120 which are used primarily in small remote control cars. We've bought a couple of KST BLS815 V8 servos which are much better so we'll see what kind of delay we see with those. Then we'll model what ever hopefully smaller delay we have in our equations of motion.
documentsdirectory contains latex files for papersexperimentsdirectory contains code to run experiments for paperflight_analysis_toolsdirectory contains code for analyzing flight data for the dronehopdirectory contains code for running NMPC control algorithm on drone with ros2, three different NLP formulations for the NMPC, and code to test the drone servos and motors.plotsdirectory holds plot pdfs produced from various programsplotter_logscontains flight data downloaded from the Raspberry Piresourcedirectory is used by ros2 buildsimulation_toolsdirectory contains code for running simulations and testing the NMPC algorithmtoolsdirectory contains general things that don't fit anywhere else
In the top level hop directory build a virtual python environment and activate it
python3 -m venv venv
source venv/bin/activate
Now we can install needed libraries
python -m pip install --upgrade pip
python -m pip install numpy
python -m pip install matplotlib
python -m pip install casadi
python -m pip install 'do-mpc[full]'
For the animation you need
python -m pip install vpython
python -m pip install numpy-quaternion
Open file run_experiments.py and uncomment the experiment you want to run. It is not recommended to run them all at once. Run the experiment in the top level directory by running
python run_experiments.py
You can also get flight data from the PixHawk by connecting to QGroundControl.
Open up a shell on the Pi with ssh.
ssh izzy@X.X.X.X
Run the MicroAgent
sudo /usr/local/bin/MicroXRCEAgent serial --dev /dev/ttyAMA0 -b 921600
When the px4 is connected you should see topics coming in.
ssh into the Pi through vscode so you can edit and use git.
Open up another shell on the Pi with ssh.
cd drone_ws
colcon build
source install/setup.bash
ros2 run hop nmpc_controller
You can run the nodes test_motors and test_servos this way as well.
Recommendation: Don't do anything other than run the code from this shell. If you want to do git stuff, do it from a different shell login. I've really screwed up our directories because I dropped down into the src/hop folder to do stuff, then forgot what directory I'm in and ran colcon build. It generates files where they shouldn't be and they end up in the git directory. We added them to the git repo by accident and it was a pain to sort it all out.
All of these default to logging = False (meaning don't log messages to the console) so you can feed in waypoints or pwm from the keyboard without seeing streams of log messages.
-
nmpc_controller: Use theukey to progress forward through waypoints. -
test_motors: Use theukey to increment pwm by$0.1$ . -
test_servos: Use theukey to increment pwm by$0.1$ andjto decrement by$0.1$
Hit any other keyboard key to exit the run
Flight data is automatically logged and logs are written to plotter_logs folder. Logs are saved to file and named with the datetime they were created and the most current log is also stored in current.json. You can pull them to your mac with the pull_and_plot.sh bash shell and run the flight analysis tools on them. It has an old IP address for the Pi so you can edit it or just copy the command.
Plot the most current run with
python plot_run.py
Make sure to source your hop directory on your mac first.
source venv/bin/activate