Skip to content
Snippets Groups Projects
README.md 6.08 KiB
Newer Older
bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed
The `quad/` directory contains all code that programs the quadcopter. This
includes any C libraries we have written, any HDL to program the Zybo on
bbartels's avatar
bbartels committed
the quad, and the XSDK main project that runs on the Zybo.

bbartels's avatar
bbartels committed
## Brief Intro
bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed
The main quad application is located at `src/quad_app/`.
bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed
To run this application on the Zybo, we need to implement the hardware drivers,
bbartels's avatar
bbartels committed
and provide a `main` function. This is done in `xsdk_workspace/real_quad/src`.
bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed
We can also run this application on our own laptops for testing. We call this
implementation the "virtual quad". This is done in `src/virt_quad`.
bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed
### Primarily Libraries and Executables

To build the libraries and executables:
bbartels's avatar
bbartels committed
```
make
bbartels's avatar
bbartels committed
```

You can also build each library individually inside their respective project
directories:
```
cd src/<project> && make
```

bbartels's avatar
bbartels committed
**NOTE**: All build artifacts will be placed in `quad/lib` or `quad/bin`
(depending on whether it is a library or executable, respectively)

### XSDK Project (what runs on the Zybo)
To build the XSDK project, use the XSDK IDE. Refer to the [Xilinx How-to](doc/how_to_use_xilinx_tools.pdf)
for more instructions. Be sure to select the `xsdk_workspace` directory in the
quad directory as your "workspace."
bbartels's avatar
bbartels committed

bbartels's avatar
bbartels committed
## Testing

bbartels's avatar
bbartels committed
### Automated Tests
_Write tests! It makes automating things so much easier._
bbartels's avatar
bbartels committed

Run the unit and functional tests:
bbartels's avatar
bbartels committed
```
make test
```

bbartels's avatar
bbartels committed
And glad to hear you are interested in writing your own unit tests! Look at the
README and examples in our simple testing library at `src/test`.

bbartels's avatar
bbartels committed
### Manually testing the hardware interface
bbartels's avatar
bbartels committed
Of course, we cannot run automated tests on code that needs the Zybo. But
bbartels's avatar
bbartels committed
we have manual tests that you can use to test each specific driver in the 
hardware interface.
bbartels's avatar
bbartels committed

Look in `xsdk_workspace/real_quad/src/hw_impl_zybo_tests.c` for instructions.
bbartels's avatar
bbartels committed
Ideally, you would run these tests from the XSDK IDE.
dawehr's avatar
dawehr committed

bbartels's avatar
bbartels committed
## Other Documents
[Zybo Pinout Assignments](doc/zybo_pinout_assignments.md)  
[How to use Xilinx software tools](doc/how_to_use_xilinx_tools.pdf)  

dawehr's avatar
dawehr committed
## XSDK FYIs
Definitely first read the [Xilinx How-To](doc/how_to_use_xilinx_tools.pdf).

dawehr's avatar
dawehr committed
The XIlinx SDK has a few quirks that are important to watch out for:
 1. From the [documentation](https://www.xilinx.com/support/documentation/sw_manuals/xilinx14_7/SDK_Doc/tasks/sdk_t_tcf_limitations_faq.htm), if you abort program execution while at a breakpoint inside an interrupt handler, when re-running the program, interrupts don’t fire. You have to do a hard reset of the board (cycle power) to have interrupts work again.
dawehr's avatar
dawehr committed
 2. After doing a `git pull` or `git checkout`, refresh the files by right-clicking on the project in the sidebar and clicking "Refresh"
 3. The project does not detect changes in header files, so if you modify a `.h` file, you should do a clean before re-building, otherwise you may experience unexpected behavior. We got into the habit of always doing a clean before a build whenever creating code that will be put on the quadcopter.

## Controller Network (Control algorithm)
bbartels's avatar
bbartels committed
First read the [documentation for the computation graph library](src/computation_graph/README.md) to understand how the graph computes functions from a directed graph.
dawehr's avatar
dawehr committed

To visualize the default control network, from the quad folder, run `make diagram` with graphviz installed, and an image of the control network will show up as `network.png` in the _src/gen\_diagram_ folder. To see the autonomous controller, you can change the call at the bottom of `control_algorithm_init` from `connect_manual()` to `connect_autonomous()` before running `make diagram`. Just be sure to change it back to `connect_manual()` before the final build. Below is a simplified version of the autonomous controller that shows the control network for autonomous flight using VRPN data. (Unused blocks relating to manual flight and optical flow have been removed, as well as Ts\_IMU and Ts\_VRPN, which are blocks that keep track of the sampling period)

![Control network](src/gen_diagram/team_17-16_demo-simple_network.png)

One potential confusing point to take note of is the difference between "(X/Y) Vel PID" and "(X/Y) Vel" blocks. "(X/Y) Vel" is just a PID controller that has Kd=-1, which results in calculating the derivative of position to provide velocity. For clarity, it would be a good idea to create an actual differentiation block.

* Note our use of derivative on value, not error
dawehr's avatar
dawehr committed

dawehr's avatar
dawehr committed
## Optical Flow
The current (end of may17-16) state of optical flow is that it can be used autonomously be uncommenting all four defines at the top of `control_algorithm.c`. It is relatively stable, but drifts over time. Setpoints do work, but yaw needs fixing (See issue #23).
dawehr's avatar
dawehr committed

dawehr's avatar
dawehr committed
We are using the PX4Flow optical flow sensor. Read more about it [here](https://pixhawk.org/modules/px4flow) and [here](https://pixhawk.org/dev/px4flow). The source code for the firmware can be found on [Github](https://github.com/PX4/Flow).
### Improvements to be made
* Compensate for rotation of sensor. The PX4Flow has the ability to enable gyroscope compensation (The firmware must be re-flashed for changes to persist), but when we tried it, the output was much worse. We then implemented our own gyroscope correction, using the complementary-filtered pitch and roll, since they will not drift over time (Using raw gyro would result in drift in position because of gyrosope angle drift). The actual data didn't look much worse, and for large, slow movements, the gyroscope compensation seemed to help prevent incorrect measurements, but it always made flight worse, probably beause of high-frequency noise. Using the complementary filter might be the cause, since it essentially high-passes the accelerometer readings, which are very noisy. We then also tried putting a low-pass filter on phi_dot and theta\_dot, but it didn't help flight. Possibly the delay added by the filter caused the correction to not align with the actual movements.
* Possibly just switch to a better optical flow sensor. This one has not had any developments in the past couple years, is hard to buy, and is poorly documented. The best documentation is to actually look in the source code, because we have found multiple discrepancies in the documentation.