robotpy-wpilib-utilities 2015.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 1.0
2
+ Name: robotpy-wpilib-utilities
3
+ Version: 2015.0.0
4
+ Summary: Useful utility functions/objects for RobotPy
5
+ Home-page: https://github.com/robotpy/robotpy-wpilib-utilities
6
+ Author: Peter Johnson, Dustin Spicuzza
7
+ Author-email: robotpy@googlegroups.com
8
+ License: UNKNOWN
9
+ Description: robotpy-wpilib-utilities
10
+ ========================
11
+
12
+ .. image:: https://travis-ci.org/robotpy/robotpy-wpilib-utilities.svg
13
+ :target: https://travis-ci.org/robotpy/robotpy-wpilib-utilities
14
+
15
+ Useful utility functions/objects for RobotPy. Must have 2015 version of
16
+ RobotPy to use this.
17
+
18
+ Contribution guidelines
19
+ =======================
20
+
21
+ This repository is intended to be a common place for high quality code to live
22
+ for "things that should be in WPILib, but aren't". The python implementation of
23
+ WPILib is intended to be very close to the implementations in the other languages,
24
+ which is where packages like this come in.
25
+
26
+ * Most anything will be accepted, but ideally full frameworks will be separate
27
+ packages and don't belong here
28
+ * Ideally, contributions will have unit tests
29
+ * Ideally, contributions will not have external python dependencies other than
30
+ WPILib -- though, this may change.
31
+ * Contributions will work (or at least, not break) on all supported RobotPy
32
+ platforms (Windows/Linux/OSX, RoboRio)
33
+ * All pull requests will be tested using Travis-CI
34
+
35
+ Installation
36
+ ============
37
+
38
+ TODO: Will be integrated into RobotPy 2015 installation somehow
39
+
40
+ License
41
+ =======
42
+
43
+ BSD License, similar to WPILib.
44
+
45
+ Authors
46
+ =======
47
+
48
+ - Dustin Spicuzza (dustin@virtualroadside.com)
49
+ - Insert your name here!
50
+
51
+ Keywords: frc first robotics
52
+ Platform: UNKNOWN
@@ -0,0 +1,41 @@
1
+ robotpy-wpilib-utilities
2
+ ========================
3
+
4
+ .. image:: https://travis-ci.org/robotpy/robotpy-wpilib-utilities.svg
5
+ :target: https://travis-ci.org/robotpy/robotpy-wpilib-utilities
6
+
7
+ Useful utility functions/objects for RobotPy. Must have 2015 version of
8
+ RobotPy to use this.
9
+
10
+ Contribution guidelines
11
+ =======================
12
+
13
+ This repository is intended to be a common place for high quality code to live
14
+ for "things that should be in WPILib, but aren't". The python implementation of
15
+ WPILib is intended to be very close to the implementations in the other languages,
16
+ which is where packages like this come in.
17
+
18
+ * Most anything will be accepted, but ideally full frameworks will be separate
19
+ packages and don't belong here
20
+ * Ideally, contributions will have unit tests
21
+ * Ideally, contributions will not have external python dependencies other than
22
+ WPILib -- though, this may change.
23
+ * Contributions will work (or at least, not break) on all supported RobotPy
24
+ platforms (Windows/Linux/OSX, RoboRio)
25
+ * All pull requests will be tested using Travis-CI
26
+
27
+ Installation
28
+ ============
29
+
30
+ TODO: Will be integrated into RobotPy 2015 installation somehow
31
+
32
+ License
33
+ =======
34
+
35
+ BSD License, similar to WPILib.
36
+
37
+ Authors
38
+ =======
39
+
40
+ - Dustin Spicuzza (dustin@virtualroadside.com)
41
+ - Insert your name here!
@@ -0,0 +1,5 @@
1
+
2
+ try:
3
+ from .version import __version__
4
+ except ImportError: # pragma: nocover
5
+ __version__ = 'master'
@@ -0,0 +1,18 @@
1
+ class DriverBase(object):
2
+ """
3
+ This should be the base class for all drivers in the cdl,
4
+ currently all it does is spit out a warning message if the driver has not been verified.
5
+ """
6
+
7
+ #:This should be overloaded by the driver,
8
+ # It is just a mechanism to ensure code quality for device drivers. Upon creation of a new driver,
9
+ # it will be either left alone, or overloaded to be False. Once the functionality of the driver is verified,
10
+ # this will get overloaded to true by whoever verifies it.
11
+ verified = False
12
+
13
+ def __init__(self):
14
+ """
15
+ Constructor for DriverBase, all this does is print a message to console if the driver has not been verified yet.
16
+ """
17
+ if not self.verified:
18
+ print("Warning, device driver {} has not been verified yet, please use with caution!".format(self.__class__.__name__))
@@ -0,0 +1,51 @@
1
+ class Unit(object):
2
+ """The class for all of the units here"""
3
+
4
+ def __init__(self, base_unit, base_to_unit, unit_to_base):
5
+ """
6
+ Unit constructor, used as a mechanism to convert between various measurements
7
+ :param base_unit: The instance of Unit to base conversions from. If None, then assume it is the ultimate base unit
8
+ :param base_to_unit: A callable to convert measurements between this unit and the base unit
9
+ :param unit_to_base: A callable to convert measurements between the base unit and this unit
10
+ """
11
+ self.base_unit = base_unit
12
+ self.base_to_unit = base_to_unit
13
+ self.unit_to_base = unit_to_base
14
+
15
+
16
+ def convert(source_unit, target_unit, value):
17
+ """
18
+ Convert between units, returns value in target_unit
19
+ :param source_unit: The unit of value
20
+ :param target_unit: The desired output unit
21
+ :param value: The value, in source_unit, to convert
22
+ """
23
+ #Convert value from source_unit to the ultimate base unit
24
+ current_unit = source_unit
25
+ current_value = value
26
+ while current_unit.base_unit is not None:
27
+ current_value = current_unit.unit_to_base(current_value)
28
+ next_unit = current_unit.base_unit
29
+ current_unit = next_unit
30
+
31
+ #Get the chain of conversions between target_unit and the ultimate base unit
32
+ current_unit = target_unit
33
+ unit_chain = list()
34
+ while current_unit.base_unit is not None:
35
+ unit_chain.append(current_unit)
36
+ next_unit = current_unit.base_unit
37
+ current_unit = next_unit
38
+
39
+ #Follow the chain of conversions back to target_unit
40
+ for unit in reversed(unit_chain):
41
+ current_value = unit.base_to_unit(current_value)
42
+
43
+ #Return it!
44
+ return current_value
45
+
46
+ #Some typical units to be used
47
+ meter = Unit(base_unit=None, base_to_unit=lambda x: None, unit_to_base=lambda x: None)
48
+ centimeter = Unit(base_unit=meter, base_to_unit=lambda x: x*100, unit_to_base=lambda x: x/100)
49
+
50
+ foot = Unit(base_unit=meter, base_to_unit=lambda x: x/0.3048, unit_to_base=lambda x: x*0.3048)
51
+ inch = Unit(base_unit=foot, base_to_unit=lambda x: x*12, unit_to_base=lambda x: x/12)
@@ -0,0 +1,83 @@
1
+ """
2
+ These are a set of drivers for the XL-MaxSonar EZ series of sonar modules.
3
+ The devices have a few different ways of reading from them, and the these drivers attempt to cover
4
+ some of the methods
5
+ """
6
+ import wpilib
7
+
8
+ from . import driver_base
9
+ from robotpy_ext.common_drivers import units
10
+
11
+
12
+ class MaxSonarEZPulseWidth(wpilib.SensorBase, driver_base.DriverBase):
13
+ """
14
+ This is a driver for the MaxSonar EZ series of sonar sensors, using the pulse-width output of the sensor.
15
+
16
+ To use this driver, pin 2 on the sensor must be mapped to a dio pin.
17
+ """
18
+
19
+ #This code has actually never been run, so it is extra not-verified!
20
+ verified = False
21
+
22
+ def __init__(self, channel, output_units=units.inch):
23
+ """Sonar sensor constructor
24
+
25
+ :param channel: The digital input index which is wired to the pulse-width output pin (pin 2) on the sensor.
26
+ :param output_units: The Unit instance specifying the format of value to return
27
+ """
28
+
29
+ #Save value
30
+ self.output_units = output_units
31
+
32
+ #Setup the counter
33
+ self.counter = wpilib.Counter(channel)
34
+ self.counter.setSemiPeriodMode(highSemiPeriod=False)
35
+
36
+ #Call the parents
37
+ super().__init__()
38
+
39
+ def free(self):
40
+ """Delete (free) the counter for the sonar sensor"""
41
+ self.counter.free()
42
+
43
+ def get(self):
44
+ """Return the current sonar sensor reading, in the units specified from the constructor"""
45
+ inches = self.counter.get()/0.000147
46
+ return units.convert(units.inch, self.output_units, inches)
47
+
48
+
49
+ class MaxSonarEZAnalog(wpilib.SensorBase, driver_base.DriverBase):
50
+ """
51
+ This is a driver for the MaxSonar EZ series of sonar sensors, using the analog output of the sensor.
52
+
53
+ To use this driver, pin 3 on the sensor must be mapped to an analog pin, and the sensor must be on a 5v supply.
54
+ """
55
+
56
+ #This code has actually never been run, so it is extra not-verified!
57
+ verified = False
58
+
59
+ def __init__(self, channel, output_units=units.inch):
60
+ """Sonar sensor constructor
61
+
62
+ :param channel: The analog input index which is wired to the analog output pin (pin 3) on the sensor.
63
+ :param output_units: The Unit instance specifying the format of value to return
64
+ """
65
+
66
+ #Save value
67
+ self.output_units = output_units
68
+
69
+ #Setup the analog input
70
+ self.analog = wpilib.AnalogInput(channel)
71
+
72
+ #Call the parents
73
+ super().__init__()
74
+
75
+ def free(self):
76
+ """Delete (free) the analog input for the sonar sensor"""
77
+ self.analog.free()
78
+
79
+ def get(self):
80
+ """Return the current sonar sensor reading, in the units specified from the constructor"""
81
+ centimeters = self.analog.getVoltage()/.0049
82
+ return units.convert(units.centimeter, self.output_units, centimeters)
83
+
@@ -0,0 +1,2 @@
1
+
2
+ from .precise_delay import PreciseDelay
@@ -0,0 +1,26 @@
1
+ """
2
+ This is a replacement event loop and policy for asyncio that uses FPGA time,
3
+ rather than native python time.
4
+ """
5
+ from asyncio.events import BaseDefaultEventLoopPolicy
6
+ from asyncio import SelectorEventLoop, set_event_loop_policy
7
+ from wpilib import Timer
8
+
9
+
10
+ class FPGATimedEventLoop(SelectorEventLoop):
11
+ """An asyncio event loop that uses wpilib time rather than python time"""
12
+ def time(self):
13
+ return Timer.getFPGATimestamp()
14
+
15
+
16
+ class FPGATimedEventLoopPolicy(BaseDefaultEventLoopPolicy):
17
+ """An asyncio event loop policy that uses FPGATimedEventLoop"""
18
+ _loop_factory = FPGATimedEventLoop
19
+
20
+
21
+ def patch_asyncio_policy():
22
+ """
23
+ Sets an instance of FPGATimedEventLoopPolicy as the default asyncio event
24
+ loop policy
25
+ """
26
+ set_event_loop_policy(FPGATimedEventLoopPolicy())
@@ -0,0 +1,36 @@
1
+
2
+ import wpilib
3
+
4
+ class PreciseDelay:
5
+ '''
6
+ Used to synchronize a timing loop.
7
+
8
+ Usage::
9
+
10
+ delay = PreciseDelay(time_to_delay)
11
+
12
+ while something:
13
+ # do things here
14
+ delay.wait()
15
+ '''
16
+
17
+ def __init__(self, delay_period):
18
+ '''
19
+ :param delay_period: The amount of time to do a delay
20
+ :type delay_period: float
21
+ '''
22
+
23
+ self.delay = wpilib.Timer.delay
24
+ self.timer = wpilib.Timer()
25
+ self.delay_period = delay_period
26
+
27
+ self.timer.Start()
28
+
29
+ def wait(self):
30
+ '''Waits until the delay period has passed'''
31
+
32
+ # we must *always* yield here, so other things can run
33
+ self.delay(0.001)
34
+
35
+ while not self.timer.hasPeriodPassed(self.delay_period):
36
+ self.delay(0.001)
@@ -0,0 +1,2 @@
1
+ # Autogenerated by setup.py
2
+ __version__ = '2015.0.0'
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 1.0
2
+ Name: robotpy-wpilib-utilities
3
+ Version: 2015.0.0
4
+ Summary: Useful utility functions/objects for RobotPy
5
+ Home-page: https://github.com/robotpy/robotpy-wpilib-utilities
6
+ Author: Peter Johnson, Dustin Spicuzza
7
+ Author-email: robotpy@googlegroups.com
8
+ License: UNKNOWN
9
+ Description: robotpy-wpilib-utilities
10
+ ========================
11
+
12
+ .. image:: https://travis-ci.org/robotpy/robotpy-wpilib-utilities.svg
13
+ :target: https://travis-ci.org/robotpy/robotpy-wpilib-utilities
14
+
15
+ Useful utility functions/objects for RobotPy. Must have 2015 version of
16
+ RobotPy to use this.
17
+
18
+ Contribution guidelines
19
+ =======================
20
+
21
+ This repository is intended to be a common place for high quality code to live
22
+ for "things that should be in WPILib, but aren't". The python implementation of
23
+ WPILib is intended to be very close to the implementations in the other languages,
24
+ which is where packages like this come in.
25
+
26
+ * Most anything will be accepted, but ideally full frameworks will be separate
27
+ packages and don't belong here
28
+ * Ideally, contributions will have unit tests
29
+ * Ideally, contributions will not have external python dependencies other than
30
+ WPILib -- though, this may change.
31
+ * Contributions will work (or at least, not break) on all supported RobotPy
32
+ platforms (Windows/Linux/OSX, RoboRio)
33
+ * All pull requests will be tested using Travis-CI
34
+
35
+ Installation
36
+ ============
37
+
38
+ TODO: Will be integrated into RobotPy 2015 installation somehow
39
+
40
+ License
41
+ =======
42
+
43
+ BSD License, similar to WPILib.
44
+
45
+ Authors
46
+ =======
47
+
48
+ - Dustin Spicuzza (dustin@virtualroadside.com)
49
+ - Insert your name here!
50
+
51
+ Keywords: frc first robotics
52
+ Platform: UNKNOWN
@@ -0,0 +1,16 @@
1
+ README.rst
2
+ setup.py
3
+ robotpy_ext/__init__.py
4
+ robotpy_ext/version.py
5
+ robotpy_ext/common_drivers/__init__.py
6
+ robotpy_ext/common_drivers/driver_base.py
7
+ robotpy_ext/common_drivers/units.py
8
+ robotpy_ext/common_drivers/xl_max_sonar_ez.py
9
+ robotpy_ext/misc/__init__.py
10
+ robotpy_ext/misc/asyncio_policy.py
11
+ robotpy_ext/misc/precise_delay.py
12
+ robotpy_wpilib_utilities.egg-info/PKG-INFO
13
+ robotpy_wpilib_utilities.egg-info/SOURCES.txt
14
+ robotpy_wpilib_utilities.egg-info/dependency_links.txt
15
+ robotpy_wpilib_utilities.egg-info/requires.txt
16
+ robotpy_wpilib_utilities.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ [egg_info]
2
+ tag_svn_revision = 0
3
+ tag_build =
4
+ tag_date = 0
5
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from os.path import dirname, exists, join
4
+ import sys, subprocess
5
+ from setuptools import setup
6
+
7
+ setup_dir = dirname(__file__)
8
+ base_package = 'robotpy_ext'
9
+ version_file = join(setup_dir, base_package, 'version.py')
10
+
11
+ packages = [
12
+ base_package,
13
+ base_package + '.misc',
14
+ base_package + '.common_drivers'
15
+ ]
16
+
17
+ # Automatically generate a version.py based on the git version
18
+ if exists(join(setup_dir, '.git')):
19
+ p = subprocess.Popen(["git", "describe", "--tags", "--dirty=-dirty"],
20
+ stdout=subprocess.PIPE,
21
+ stderr=subprocess.PIPE)
22
+ out, err = p.communicate()
23
+ # Make sure the git version has at least one tag
24
+ if err:
25
+ print("Error: You need to create a tag for this repo to use the builder")
26
+ sys.exit(1)
27
+
28
+ # Create the version.py file
29
+ with open(version_file, 'w') as fp:
30
+ fp.write("# Autogenerated by setup.py\n__version__ = '{0}'".format(out.decode('utf-8').rstrip()))
31
+
32
+ if exists(version_file):
33
+ with open(join(setup_dir, base_package, 'version.py'), 'r') as fp:
34
+ exec(fp.read(), globals())
35
+ else:
36
+ __version__ = 'master'
37
+
38
+ with open(join(setup_dir, 'README.rst'), 'r') as readme_file:
39
+ long_description = readme_file.read()
40
+
41
+ setup(
42
+ name='robotpy-wpilib-utilities',
43
+ version=__version__,
44
+ description='Useful utility functions/objects for RobotPy',
45
+ long_description=long_description,
46
+ author='Peter Johnson, Dustin Spicuzza',
47
+ author_email='robotpy@googlegroups.com',
48
+ url='https://github.com/robotpy/robotpy-wpilib-utilities',
49
+ keywords='frc first robotics',
50
+ install_requires=['wpilib'],
51
+ packages=packages,
52
+ )