Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gps.py part #992

Merged
merged 20 commits into from Apr 22, 2022
Merged

Add gps.py part #992

merged 20 commits into from Apr 22, 2022

Conversation

Ezward
Copy link
Contributor

@Ezward Ezward commented Mar 6, 2022

Part of Issue #991

  • reads gps coordinates as tuple (timestamp, longitude, latitude)
  • can be run in a thread
  • main self test logs gps coordinates
  • self test will also capture waypoints, model them statistically, plot them and do several kinds of hit tests against them. This really good for getting your gps setup well.

@Ezward Ezward requested review from zlite and DocGarbanzo March 6, 2022 21:49
@Ezward Ezward self-assigned this Mar 6, 2022
@Ezward
Copy link
Contributor Author

Ezward commented Mar 7, 2022

Note the changes to install; I'm having trouble testing them because of the conda issue with solving the environment.

Copy link
Contributor

@DocGarbanzo DocGarbanzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks great, very good and clear/readible code. I only have a couple of minor comments.

import utm

logger = logging.getLogger("gps")
logger.setLevel(logging.DEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set the logging level only in manage.py and then all parts will log according to that level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, left over debugging code. Thanks

line = self._readline()
if line:
if self.debug:
logger.info(line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you would say logger.debug(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually want this to log at info level, but only if debugging is turned on. I don't want to turn on all debug level logs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that having the functionality of the logging module which allows a very fine grained adjustment of which messages in which modules will perform logging is contradictory to having an additional boolean debug flag here. So you would make this a debug statement here.

Copy link
Contributor Author

@Ezward Ezward Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging module won't do what I want unless I can set the level per logger, which itself is a pain; we could setup a logging configuration file to make this happen, but this is simple and does what I need. See more comments below.

donkeycar/parts/gps.py Show resolved Hide resolved
if self.gps is not None:
with self.lock:
try:
if self.gps is not None and self.gps.is_open:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.gps has already been checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this.

if self.lock.acquire(blocking=False):
try:
# TODO: Serial.in_waiting _always_ returns 0 in Macintosh
if self.gps is not None and self.gps.is_open and self.gps.in_waiting:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.gps has been checked already

"""
Calculate (min, max, mean, std_deviation) of a list of floats
"""
if data is None or len(data) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not data:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

donkeycar/parts/gps.py Show resolved Hide resolved
donkeycar/parts/gps.py Show resolved Hide resolved
- moviepy
- install -U --no-deps numpy==1.19.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this does not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this to make it a legal set of arguments for pip install

- psutil
- kivy=2.0.0
- plotly
- pyyaml
- fastai
- pip:
- tensorflow==2.2.0
- --no-binary :h5py: h5py==3.1.0
- tensorflow==2.5.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be these changes crept in accidentally, they don't look right....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this so it is legal arguments to pip install. These have been tested using pip directly. However, I can't test this using the standard install instructions because conda never resolves the environment; after 12 hours I quit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot get the conda install instructions to work at all. I got a pip install script to work on mac, but I did have to install h5py this way so it would build and tensorflow 2.2.0 is not longer available. I think we need to do some basic testing on the install in all the environments; I think the RPi is broken because of tensorflow 2.2.0 as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be happy to back out all the setup changes and we can deal with them in a separate pull request to fix the install issues on every platform.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please revert those change, the Mac conda environment runs well on the CI as well as on my computer. If the RPi install gives a problem then we need to address this differently, as the RPi installs through pip (using setup.py) only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted mac.yml to be same as main.

@Ezward Ezward requested a review from DocGarbanzo March 16, 2022 18:07

logger = logging.getLogger("gps")

class gps:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that: class names should be upper/camel case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it Gps as GPS looks like a constant.

import serial
import utm

logger = logging.getLogger("gps")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use __name__ as the name of the logger, it won't inherit the settings from the base logger (actually any base logger in the hierarchy).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed that. Thanks.

donkeycar/parts/gps.py Show resolved Hide resolved
line = self._readline()
if line:
if self.debug:
logger.info(line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that having the functionality of the logging module which allows a very fine grained adjustment of which messages in which modules will perform logging is contradictory to having an additional boolean debug flag here. So you would make this a debug statement here.

#
parts = gps_str.split(".")
degrees_str = parts[0][:-2]
minutes_str = parts[0][-2:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I think you don't need to do any split here: just

degrees = float(gps_str[:2])
minuts = float(gps_str[2:])

donkeycar/parts/gps.py Show resolved Hide resolved
- psutil
- kivy=2.0.0
- plotly
- pyyaml
- fastai
- pip:
- tensorflow==2.2.0
- --no-binary :h5py: h5py==3.1.0
- tensorflow==2.5.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please revert those change, the Mac conda environment runs well on the CI as well as on my computer. If the RPi install gives a problem then we need to address this differently, as the RPi installs through pip (using setup.py) only.

@Ezward Ezward requested a review from DocGarbanzo March 22, 2022 05:08
@@ -49,7 +49,10 @@ def package_files(directory, strip_leading):
'progress',
'typing_extensions',
'pyfiglet',
'psutil'
'psutil',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add these to 3 libraries to the conda yaml files.

@DocGarbanzo
Copy link
Contributor

@Ezward - everything looks good, I think we need to bump the version (rebase from main) and update the conda yaml files.

Ezward and others added 17 commits April 8, 2022 22:57
- reads gps coordinates as tuple (timestamp, longitude, latitude)
- note that currently it is not able to check for buffered
  chars on the mac; the Serial.in_waiting always returns 0.
- this is a problem; it would be better to have the loop
  continue if no chars are waiting, rather than block.
- I will test this on raspberrypi and nano and see if
  i can get that feature to work
- Serial.in_waiting always returns 0 on mac, but it works on
  raspberrypi os, so I added it back in.
- Added plotting of the waypoints, their bounds and ellipse
- Added separate hit tests for bounds, ellipse and axis-aligned
  standard deviation.
- limit self.debug checks to those that should only happen using the __main__ self test.
- I have successfully used these options directly with pip
- I cannot test them directly because conda will not resolve the dependencies
- we will deal with mac install issues in a separate issue
- logger had syntax error
- modern gps use 'GNRMC' message, which is standard
- based on multiple of standard deviation
@Ezward
Copy link
Contributor Author

Ezward commented Apr 9, 2022

@Ezward - everything looks good, I think we need to bump the version (rebase from main) and update the conda yaml files.

I did that and updated the conda yaml files, but I have not tested these yet.

@Ezward Ezward requested a review from DocGarbanzo April 9, 2022 16:55
Copy link
Contributor

@DocGarbanzo DocGarbanzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - need to wait until checks passed.

setup.py Outdated
@@ -24,7 +24,7 @@ def package_files(directory, strip_leading):
long_description = fh.read()

setup(name='donkeycar',
version="4.3.10",
version="4.3.11",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just merged your other PR which bumped the version to 4.3.11 - can you rebase and force-push?

donkeycar/parts/gps.py Show resolved Hide resolved
@DocGarbanzo DocGarbanzo merged commit e1083e4 into main Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants