Crazyflie 2 with GPS

Firmware/software/electronics/mechanics
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,

This is an update to summarize the repository branches containing the uploaded source code
on this project to-date:

>>>>Branch gtgpsTab - The 1st commit contains the GlobalTop Titan-2 GNSS deck driver and
magnetometer (compass) controller that provides state->attitude/yawgeo = +/- 180 degrees
positive is counterclockwise. The #define GPS_Present is active in stabilizer_types.h. Also,
the altitude hold mode code is untouched and is the original thrust-based method for setting
the desired altitude. This commit contains the original pid.h values.

>>>>Branch gtgps-2 - The 2nd commit contains the new altitude hold mode code which
uses the altimeter sensor position to set the desired altitude. The #define GPS_Present
is inactive in stabilizer_types.h and removes the call to the gps deck drive in sensors_stock.c
and the call to the compassController() in stabilizer.c. The Magnetometer sensor data is not
processed. This commit contains the more aggressive pid.h values.

>>>>Branch gtgps-3 - This 3rd commit contains the same code as in the 2nd commit except
the #define GPS_Present is active in stabilizer_types.h. This enables the sensors->position to
contains the gps latitude, longitude and height above mean sea level when there is a 3D Fix
or 3D/DGPS Fix. In addition, magnetometer-based yaw is placed in state->attitude/yawgeo.
As in the 2nd commit the desired altitude using the altimeter is used in the altitude hold mode.
This commit contains the more aggressive pid.h values used in the attitude roll/pitch controller.

By the way, one method to eliminate the gyro drift in the crazyflie is by biasing the yaw
(state->attitude.yaw) to agree with yawgeo (state->attitude.yawgeo). The magnetometer
of course does not have an inherent drift.

Best regards,
Jack
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie 2 with GPS

Post by tobias »

Very interesting Jack!

I tried your code quickly last Friday but couldn't get the values to show up in the client. Didn't have time to debug so it might have been trivial. I also updated the Titan2 module with the latest binary from glabaltop, it worked with a real FTDI cable however it failed when downloading the ROM which I think it shouldn't have anyway?

I should bring Aranud into this topic as he is currently working on position control for the LPS system. Would be good to sync the work, will be more efficient to do so ;).
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,

A few minor points that perhaps should be illuminated. (1) A solution was found for the GpsTab.py not working in client-python and this was included in the work-in-progress code uploaded to GitHub. (2) Also, a change was made to inputreaderinterface.py to add deadband zeroing when the roll and pitch sticks are at their default center positions on a flight controller device. This will eliminate a slow drift in the crazyflie maintaining a horizontal xy position when the sticks are a few degrees different from zero. (3) Modules position_pid.c, estimator_complementary.c are missing the header public license comments.

Best regards,
Jack
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,

Added Branch gtgps-4 to Github repository containing latest code base which includes a correction to sensors_stock.c, adding pid.h aggressive values, and a change to compass.c log group yawgeo output to now be counterclockwise. Also, correcting position_controller_pid.c configuration control issue.

Best regards,
Jack
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,

Branch gtgps-5 was removed on 2016.06.24.
Added Branch gtgps-5 to Github repository containing latest code base which includes the planned modifications to function commanderGetSetpoint() in commander.c for setting up position hold mode when gps is present and positions are available out of the deck gtgps driver. This change is in the work-in-process phase and has yet to be validated by testing. The pid tuning values in position_controller_pid.c (.pidX & .pidY) are untouched, and may require changes in the future.

Best regards,
Jack
Last edited by jackemoore on Thu Jun 23, 2016 7:22 pm, edited 1 time in total.
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,

Branch gtgps-6 was removed 2016.06.24.
Added Branch gtgps-6 to Github repository containing latest code changes supporting the position hold mode evaluation. This commit contains the latest updates that supports the gtgps, compass, compass calibration, gyro yaw drift elimination, altitude hold and position hold features. The github crazyflie-firmware dated 2016.05.19 is still the baseline code for these updates. This is still in the work-in-process state and has yet to be validated by thorough testing of the actual flight performance. In summary, (a) a bug fix was applied to position_controller_pid.c, (b) gtgps.c was updated to better define when a position fix can be used for position hold purposes, (c) compass calibration values are saved in eeprom when calibration is performed in conjunction with the Xbox350 controller and read back whenever there is a subsequent powering up of the crazyflie, (d) added gyro yaw bias using the compass to eliminate gyro drift and reorient to geographic north, (e) the watchdog timer is disabled and not used, (f) added experimental PID settings in pid.h that result in a faster and tighter control of the CF2 attitude, (g) the gyro bias calculation has been improved in imu_cf2.c as updated in github 2016.06.17, and (h) control->thrust now has tilt compensation in controller_pid.c as updated in github 2016.06.17. It has been found that recent updates of the github firmware (after 2016.05.19) are currently not compatible with the gtgps using uart1 serial port communication.

Best regards,
Jack
Last edited by jackemoore on Thu Jun 23, 2016 7:21 pm, edited 1 time in total.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie 2 with GPS

Post by tobias »

Got the gtgps-6 branch to work now, yay! Just flashed the provided zip and copied the changes into a cfclient where I checked out hash 6d6e340576faac254d2b4c77fc52e467adb7a910 (2016-05-12). Would be great though if you did a fork of the CF2 firmware and cflient repos. Then it will be a lot easier for me to test and debug. It will also be a lot easier to submit it back to the main repo with a pull request later on.

It is raining now so it is kind of a bad idea to test the position hold feature but I'm really looking forward to it! By the way how do I activate?
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,
What was Branch gtgps-7 was removed and is now gtgps-5 as of 2016.06.24.

Added Branch gtgps-5 to Github repository:

http://Github.com/jackemoore/New-GPS-Additions

This commit contains the latest updates as well as the whole python3.4 source code, the whole cfclient source
code, and the whole cf2 firmware containing the gtgps deck driver. These have been tested in a windows 7 & windows 10 pc environment.
In addition, the earlier branch gtgps-6 that incorporated gyro.yaw drift corrections using the magnetometer sensor and converting the
gyro.yaw to geographic north reference, this new commit applies gyro drift correction but leaves the gyro.yaw referenced to the cf2
power-on reference heading at zero degrees. The code changes in compass.c attempt to minimize passing on sensor data noise from the
magnetometer onto the gyro.yaw estimates while at the same time striving to remain responsive to instantaneous changes in the crazyflie
heading. The sensor fusion aspects are still work-in-progress to find a good tradeoff of limiting noise entering the drift correction
without compromising gyro heading sensitivity.

Using my Xbox360 controller, altHoldMode is enabled pressing and holding the left bumper (id = 4) and posHoldMode is enabled by pressing and holding the right bumper (id = 5).

To facilitate running the compass calibration, the steps using the Xbox360 are as follows: (1) press the start button (id = 7 or calButton), (2) press the A button (id = 0 or horzButton) and turn around 360 degrees holding the cf2 horizontally level (maybe 15 seconds duration). When finished press the start button again. (3) press the B button (id = 1 or vertButton) and turn around 360 degrees holding the cf2 vertically, for example nose down or minus 90 degrees pitch, (maybe 15 seconds). When finished press the start button again. That completes the calibration and the cal values are saved in eeprom and stay there until the next time the bootloader flashes a new firmware. From the plotter, the compassCal variables (calRequired & magcalOn) can be monitored as the steps are executed. The compassCal variables yawangle or yawgeo are both referenced to geographic north. In the compass.c module, magnetic declination should be setup for the local operating (geographical) area.

Compass calibration must be performed at least once before the posHoldMode can correctly apply lat/lon coordinates to the roll/pitch adjustments of the crazyflie.

Currently, the gtgps driver doesn't make available lat/lon values for posHoldMode until there is a gps 3D fix (fixtype > 2), there are at least 5 satellites (nsat >= 5) in the fix solution, and the horizontal accuracy (hAcc <= 2.0) is 2.0 meters or better.

Best regards,
Jack
Last edited by jackemoore on Thu Jun 23, 2016 7:25 pm, edited 2 times in total.
jackemoore
Member
Posts: 75
Joined: Mon Apr 06, 2015 6:47 pm

Re: Crazyflie 2 with GPS

Post by jackemoore »

Hi,

In parallel with working with the GlobalTop Titan-2 gps receiver, I've also been working with the Ublox Max M8c Pico Breakout gps receiver. So, I've added a branch to my work-in-progress gitHub repository that includes the source code unique to the Ublox receiver and its deck driver.

What was dkgps-7 was removed and is now dkgps-5 as of 2016.06.24.

A new Branch dkgps-5 (not to be confused with gtgps-5) contains the latest firmware updates for the uBlox Max M8c Pico Breakout with Chip Antenna gps receiver. The firmware is identical to that of Branch gtgps-5 for the GlobalTop Titan-2 gps receiver, except for the deck driver (which is now dkgps.h & dkgps.c), the config.mk (which is now CFLAGS += -DDECK_FORCE=bcDKGPS), the makefile (which is now dkgps.o), and the corresponding changes in sensors_stock.c (which is now #include "dkgps.h" and function call (which is now dkgpsGetFrameData() ). In all other aspects the altitude hold mode using the altimeter sensor, the position hold mode using gps, the compass using the magnetometer sensor with tilt compensation & compass calibration in concert with using the controller device (currently Xbox360), and gyro.yaw drift mitigation using the compass is at the same code level as that of the gtgps.

The gtgps receiver with its integrated patch antenna is superior to that of the dkgps receiver with its chip antenna as far as gps satellite signal reception. It is less susceptible to crazyflie electrical interference, can be mounted closer to the crazyflie control board, and may yield a faster time to first 3D fix solution. The primary advantage of the dkgps gps receiver is less weight (a savings of ~4.5 g) which yields a higher crazyflie lift to weight ratio, and longer flight times.

Best regards,
Jack
Last edited by jackemoore on Thu Jun 23, 2016 7:26 pm, edited 2 times in total.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie 2 with GPS

Post by tobias »

Quickly tested the gtgps-7 branch and the first thing I noticed while flying is that the yaw is uncontrollable. I didn't calibrate the magnetometer so that might be the main problem however I also know that the current in the battery effects the magnetometer reading. Did you mount the battery underneath the CF2 to cope with this problem?

As I only have a few more minutes I'll quickly dig in to the UART problem.
Post Reply