Skip to content

PRGCorgi

Nitin J. Sanket edited this page May 14, 2020 · 8 revisions

Hardware and Software Setup for the PRGHusky

Table of Contents

Notes about Corgi dog

1. PRGCorgi Configuration

PRGCorgi comes in the following configurations (Click on the name for hardware and software setup).
Config Autopilot Software
PRGCorgiAlpha Ardupilot

2. What Is PRGCorgiAlpha?

PRGCorgiAlpha is a 180 - 210 mm size micro quadrotor built from scratch using the Ardupilot based flight controllers.

3.1. Bill Of Materials

Item Qty Price/Item (USD) Cost (USD) Sourcing Link(s)
EMAX MT2206 1900 KV Motors 4 17 68 Link
Lumenier 35A 4In1 ESC 1 60 60 Link
Optical Flow Module 1 13 13 Link
TFMini Lidar Module 1 45 45 Link
Carbon Fiber 200mm x 300mm x 2mm 1 26 26 Link
Tattu 3S Battery 2300mAh 1 36 36 Link
Spektrum DSMX Reciever 1 23 23 Link
Holybro Kakute F7 AIO V1.5 Flight Controller 1 50 50 Link
Intel Up Core 1 169 169 Link
Pololu 5V 5A Regulator 1 15 15 Link
RayCorp 5045x3 Propeller 1 15 15 Link
Spektrum DXe Transmitter 1 63 63 Link

Note that the above table represents the Bill Of Materials for the cheapest setup which are tested. Some alternate motor and ESC choices are given in the following tables which might give better performance at a higher cost.

Item Qty Price/Item (USD) Cost (USD) Sourcing Link(s) Propeller Pairing
T-Motor F40-PROII 2600 KV Motors 4 25 100 Link 5050x3
iFlight XING X2206 2750 KV Motors 4 19 76 Link 5045x3
EMAX RS2205S 2600 KV Motors 4 17 68 Link 5045x3

3.1.1. Details On Required Bolts, Nuts and Standoffs

Coming Soon.

3.1.2. Tools And Miscellaneous Items Required

3.2. Where Can I Get Water-jet Cutting And 3D Printing Done?

For University of Maryland, College Park students use Terrapin Works service and submit jobs through Papercut server. Others can use an online service such as this and this or use your own 3D printer/water-jet cutter.

3.3. Assembly Instructions

3.3.1. Wiring Instructions

Wiring for the PRGWhippetAlpha is divided into three steps, these three steps help diagnose the hardware problems early.

The first step is the bare minimum to fly a manual quadrotor. This is similar to a racing quadrotor. This step should help obtain a basic tune before trying out any autonomy functionality.

Once the aforementioned connections are made, please follow the instructions in Sections 3.4.1.1 to 3.4.1.3.

Now assuming you have a stable manually flying quadrotor, now it's time to get into some autonomy. First step is to hold altitude using a TFMini Lidar. The TFMini is connected to the KakuteF7AIO using a serial connection as shown below.

Now, go to Section 3.4.1.4 for software setup instructions.

Now, we have AltHold working perfectly, i.e., the vehicle can hold altitude on it's own using the feedback from the TFMini. Next, we want to hold position in full 3D as well. For this we will need to connect the PX4Flow sensor. In our experience, PX4Flow v1.3.1 from Hobbypower worked the best.

Connect the PX4Flow as shown below.

Now, go to Section 3.4.1.6 for software setup instructions.

3.3.2. Hardware Assembly

3.4. Software Setup

3.4.1. ArduPilot Setup

3.4.1.1. Flashing Firmware with Bootloader

Download the arducopter firmware with bootloader arducopter_with_bl.hex from here.

To flash the arducopter firmware with bootloader you need to download the Betaflight configurator chrome app from here. You'll need Google Chrome web browser for this step. If you don't have Google Chrome, please download it from here.

Now, follow the instructions from the offical Kakute F7 AIO Manual to install the drivers for your particular operating system. Though Windows is the hardest to get to work, we suggest using Windows since it had the most stable performance in our experience.

Now, press and hold the DFU button as shown below on the Kakute F7AIO while you plug in the USB to your computer. (If you don't see DFU in Betaflight, please follow this instruction.

Now, open the Betaflight configurator chrome app, it should say DFU on the top right corner as shown below. If this is not the case, follow the previous steps again carefully.

Now, select the correct board KakuteF7, check Full chip erase and click on Load Firmware [Local] on the bottom right corner as shown below (Image Credits: OscarLiang.com). Then select the arducopter_with_bl.hex file we downloaded before.

The click on Flash Firmware once the loading is complete. Wait for the firmware to complete flashing.

If you have done all the previous steps correctly, the flight controller should show a COM port on the top right. The COM port will have different names based on the operating system you are on. Now, proceed to the next step if everything worked else repeat previous steps.

3.4.1.2. Calibration with Arducopter

Download Mission Planner for Windows from here. Note that this is officially supported on Windows for now. However, many people have gotten it to work on Linux, more details about this can be found here.

Now, follow the steps here to calibrate your accelerometer.

Now, follow the steps here to calibrate your RC transmitter after binding with your reciever.

3.4.1.3. Motor Test and first flight

Now, test the motors following the instructions here, if the order is wrong, please verify the motor connections for your ESC (the connections shown in our diagram in Section 3.4.1.1 are for Lumenier 35A 4in1 ESC).

If any of the motors spin in the wrong direction, i.e., opposite to the one shown below, swap any two of the three wires for that particular motor which connect to the ESC.

Once all the motors are in the correct order and they spin in the correct direction, calibrate the ESCs by following the instructions here.

Now, change the following parameters so that you start off with a reasonably stable quadrotor and hopefully will not crash.

Parameter Value Notes
ATC_ANG_RLL_P 4.5 Stabilize Roll (Error to Rate)
ATC_ANG_PIT_P 4.5 Stabilize Pitch (Error to Rate)
ATC_ANG_YAW_P 4.5 Stabilize Yaw (Error to Rate)
ATC_RAT_RLL_P 0.135 Roll Rate Controller P Gain
ATC_RAT_RLL_I 0.09 Roll Rate Controller I Gain
ATC_RAT_RLL_D 0.0036 Roll Rate Controller D Gain
ATC_RAT_PIT_P 0.135 Pitch Rate Controller P Gain
ATC_RAT_PIT_I 0.09 Pitch Rate Controller I Gain
ATC_RAT_PIT_D 0.0036 Pitch Rate Controller D Gain
ATC_RAT_YAW_P 0.18 Yaw Rate Controller P Gain
ATC_RAT_YAW_I 0.018 Yaw Rate Controller I Gain
ATC_RAT_YAW_D 0 Yaw Rate Controller D Gain
ATC_RAT_RLL_FILT 20 Roll Rate Controller Filter Frequency
ATC_RAT_PIT_FILT 20 Pitch Rate Controller Filter Frequency
ATC_RAT_YAW_FILT 2.5 Yaw Rate Controller Filter Frequency
ATC_RAT_RLL_IMAX 0.5 Roll Rate Controller Filter I gain maximum
ATC_RAT_PIT_IMAX 0.5 Pitch Rate Controller Filter I gain maximum
ATC_RAT_YAW_IMAX 0.2 Yaw Rate Controller Filter I gain maximum
SCHED_LOOP_RATE 400 Main Control Loop Frequency
INS_GYRO_FILTER 20 Filter Cutoff Frequency for Gyroscopes
EK2_ENABLE 1 Enable EKF2 Computation for State Estimation
AHRS_EKF_TYPE 2 Use EKF2 state estimates for attitude and position control
MAG_ENABLE 0 Disable Magnetometer
EK2_MAG_CAL 2 Disable Magnetometer calibration on the fly
LOG_BITMASK 0 Disable Logging
COMPASS_USE 0 Disable Compass
COMPASS_USE2 0 Disable Compass 2
COMPASS_USE3 0 Disable Compass 3
ARMING_CHECK 0 Disable PreArm Checks
FS_CRASH_CHECK 0 Disable Crash Detection

By default, your quadrotor should follow the Mode 2 convention, i.e., left stick up/down controls throttle, left stick left/right controls Yaw, right stick up/down controls pitch and right stick left/right controls roll. If any of these are flipped, you can flip the channel in your RC Transmitter or by setting RCn_REVERSED flag to 1 in Mission Planner. By default RC1 is set to Roll, RC2 is set to Pitch, RC3 is set to Throttle and RC4 is set to Yaw. Note that RC1 to RC4 doesn't map to reciever 1 though 4 directly, in fact they are reversed in Mode 2, i.e., RC1 -> CH4, RC2 -> CH3, RC3 -> CH2 and RC4 -> CH1 (Mode details can be found here). In short, for default settings, CH1 to CH4 on the trasmitter should control Throttle, Roll, Pitch and Yaw respectively. Make sure that channel directions are correct and not flipped before you fly, i.e., stick up/right should increase and stick down/left should decrease the value. If for some reason you don't like Mode 2 or want custom RC Mappings you can follow the instructions here.

Now, go ahead and fly in your quadrotor in Stabilise mode an open area outdoor or in a netted area indoor. Make sure to fly atleast 1 m over the ground and 1 m under the ceiling to avoid any ground/ceiling effect. If you quadrotor has a lot of oscillation, tune the quadrotor in Acro mode (not stabilize) to dampen out the oscillations. DO THIS STEP BEFORE YOU PROCEED TO ANY AUTONOMY FUNCIONALITY.

If you see mid throttle oscillations and they don't dampen even after excessive tuning of PIDs and/or INS_GYRO_FILTER and/or ATC_RAT_RLL_FILT and/or ATC_RAT_RLL_FILT and/or ATC_RAT_PIT_FILT and/or ATC_RAT_YAW_FILT you might want to soft-mount your motors as described in this video.

3.4.1.4. AltHold Mode

Go back to Section 3.3.1 for the wiring diagram to connect the TFMini Lidar, which we'll use to hold altitude. Set the following parameters to start using TFMini (Use the search bar in Full Parameter List tab in CONFIG\TUNING tab in Mission Planner). Here we connected the TFMini to UART2, please adapt the SERIAL number if you changed the UART port.

Parameter Value Notes
SERIAL2_PROTOCOL 9 Rangefinder
SERIAL2_BAUD 115 115200
RNGFND1_TYPE or RNGFND_TYPE 20 Benewake TFMini
RNGFND1_MIN_CM or RNGFND_MIN_CM 30 Min. dist that rangefinder can reliably read in cm
RNGFND1_MAX_CM or RNGFND_MAX_CM 1000 (indoors) or 600 (outdoors) Max. dist that rangefinder can reliably read in cm
RNGFND1_GNDCLEAR or RNGFND_GNDCLEAR 10 Distance of sensor from ground when vehicle is landed

Restart your flight-controller by power cycling and disconnecting the USB cable. You should see the sonarrange values changing in Status tab of Mission Planner when you move the vehicle/TFMini.

Note that to have quick access to this parameter you can right click on the numbers in the quick access tab in Mission Planner and change the number or rows and columns as shown below.

The double click any icon and check the parameter you want to be displayed there as shown below.

Now, go to Initial Setup > Flight Modes and change one of the modes to AltHold as shown below.

Also, before you fly change a few EKF parameters which is used for state estimation shown below.

Parameter Value Notes
EK2_ALT_SOURCE 1
RNGFND1_MAX_CM or RNGFND_MAX_CM 1000 1000 for indoors and 600 for outdoors
RNGFND1_GNDCLEAR or RNGFND_GNDCLEAR 10 distance of sensor from ground when vehicle is landed
EK2_GPS_TYPE 3 Do not use GPS as we are indoors
EK2_RNG_USE_HGT 70 Use this percentage as range finder measurements as primary height source

Take off in Stabilize mode, once you are about 1 m high and reasonably stable, switch to AltHold mode when the throttle stick is at about 50% (while doing this for the first time, make sure you have enough headroom). Now the quadrotor should hold altitude requiring minimal adjustments in roll, pitch and yaw. You can adjust the ascent/descent rate by moving the throttle stick up/down respectively. If the AltHold mode is very sensitive to throttle mid stick you can increase the dead-band (the larger the value the mode play you have with throttle sitck when AltHold will be active without ascending/descending) by changing the value of THR_DZ in Mission Planner.

Once AltHold is works well, try the autotake off feature in AltHold mode as follows.

Start in AltHold mode and try to take off by moving throttle slowly to about 50% throttle, the quadrotor should slowly takeoff and hold altitude requiring minimal adjustments in roll, pitch and yaw. As again, you can adjust the ascent/descent rate by moving the throttle stick up/down respectively. You can land the quadrotor by moving the throttle stick slowly down.

If your gains are still not perfect, proceed to Section 3.4.1.5. for autotuning your gains. If everything works well, we are can proceed to holding position using the optical flow sensor coupled with the TFMini Lidar. Now, go to Section 3.3.1 for wiring instructions of the Flow sensor.

3.4.1.5. (Optional) Fine-tune PIDs using Autotune

Coming Soon.

3.4.1.6. FlowHold Mode

The first step is to download a custom firmware which will force enable the CX-OF flow to work on the Kakute F7AIO and also fix a bug which makes optical flow values only appear on dataflash logs but not on ground control station (Mission Planner). The optical flow focing fix was suggested in this blog post and comes from the fact that Kakute F7AIO is not defined in ardupilot/libraries/AP_HAL/AP_HAL_boards.h The flow values not showing on ground control station fix was suggested in this blog post and should be fixed in Ardupilot 4.0.0 and above. Download the custom arducopter firmware v3.6.11 with this fix from here.

Remove the props.

Then, connect the USB to the Kakute F7AIO, don't forget to power everything from a battery first as the USB port doesn't provide enough power to power up everything.

If you see any errors you might have to calibrate the accelerometer again as given in Section 3.4.1.2. Also, note that the Flow sensor might not work if it is not getting altitude measurements from the TFMini Lidar.

Change the following parameters for the flow sensor to work. If you have connected your flow sensor to a different serial port adapt the number accordingly.

Parameter Value Notes
FLOW_ENABLE 1 Read optical flow data
SERIAL3_BAUD 19 19200 baud rate
SERIAL3_PROTOCOL 18 Optical flow

Now, power cycle the system.

Now, if you don't see any errors go to Status tab and look for opt_m_x, opt_m_y values as shown below, they should be non zero and should change if you move your vehicle (with the flow sensor attached) around.

Once you're seeing changing flow values, you can mount the flow sensor as described next.

Here's the flow sensor direction for reference.

Mount the flow sensor such that +Y points to front of the quadrotor. If not adjust the FLOW_ORIENT_YAW parameter to reflect this angle.

If you change either of FLOW_ORIENT_YAW, power cycle your entire system and also unplug and replug your USB to your flight controller. Finally ensure that you are seeing changing values of opt_m_x, opt_m_y in the Status tab before you proceed. This is super important!.

Finally, set the following flags to use optical flow in EKF2:

Parameter Value Notes
EK2_GPS_TYPE 3 Do not use GPS as we are indoors
EK2_FLOW_DELAY 80 Flow valus delay by this much from IMU in ms

Now, change one of your flight modes in Config/Tuning > Flight Modes to FlowHold. It is highly recommended that you have one mode as Stabilize, other one as AltHold and preferably they are in this order Stabilize > AltHold > FlowHold as you don't want to accidently switch to FlowHold directly from Stabilize mode.

Unplug your quadrotor from the PC, place the quadrotor outdoor or in a netted area indoor. Arm it in Stabilize mode, fly upto a meter high and switch to AltHold mode, the quadrotor should be holding altitude which requires minor correction from the user for keeping it in place. Now, when the quadrotor is almost stable switch it to FlowHold mode, you should have a quadrotor which can hold position on its own.

If your quadrotor is oscillating then change FHLD_FILT_HZ to 2.

Viola you just built a quadrotor which can perform position hold autonomously, all on its own without the need of an external motion capture system.

Note that Loiter and PosHold mode should ideally work in a similar way, but currently these modes have bugs and don't work as they should with Kakute F7AIO.