Commit Graph
221 Commits
Author SHA1 Message Date
Laurens Valk 4319b2fad8 api/common/Light: add blink and animate 2020-08-25 13:38:09 +02:00
Laurens Valk 0fb150be19 api/common/LightGrid: add animate method 2020-08-25 13:37:54 +02:00
Laurens Valk 6d0984f5fc api/common/LightGrid: simplify image method
Now it just displays a Matrix/2D list. We can omit manipulations like clear=False. Composing can be done by simply adding two matrices instead.

We also drop the compressed format. Instead we could have a helper function that gives you a
matrix based on a list of integers in the now-deleted format.
2020-08-25 12:42:14 +02:00
Laurens Valk b708fe283c api/common/LightGrid: rename char argument
This follows a change in the unreleased implementation.
2020-08-25 12:42:14 +02:00
Laurens Valk 74d59b43ac api/common/LightGrid: revise text method
Specify on and off time for consistency with future blink method.

Adding some off time helps reading text with subsequent charachters that are the same. For example, now "Hello" reads H e l l o instead of Helo.

Also drop wait argument for now because it is not currently implemented and may never be.
2020-08-25 12:42:10 +02:00
Laurens Valk 1eb75e24e7 api/parameters/Color: generalize color type
First step towards making a color type with HSV representation.

Colors such as Color.RED or Color.BLUE continue to exist, but now you
can also define your own colors:

DARK_RED = Color(h=0, s=100, v=50)
2020-08-12 12:18:24 +02:00
Laurens Valk 4d88fbbbd2 api/pupdevices/PFMotor: DCMotor functionality
This replaces the on-off method in ColorDistanceSensor.remote()
with a PFMotor class that works just like the DCMotor class. This
provides much more functionality without having to invent a new API.
2020-08-11 12:05:53 +02:00
Laurens Valk 70ffbfa4f3 doc/parameters/Color: sort colors by hue/value 2020-08-10 11:39:56 +02:00
Laurens Valk c987bc2f80 api/parameters/Color: add CYAN, MAGENTA, GRAY 2020-08-10 11:34:58 +02:00
Laurens Valk 7b8a848c61 api/parameters/Color: remove BROWN
Brown has the same hue as orange, just with a lower value and/or
saturation,  so it does not need to have a separate Color instance.
It is also not supported by the color_map methods.

It was originally included in this list because the EV3 Color Sensor
can technically detect it. This is not reliable, however, as it is
also reports this value for orange objects at a slightly larger
distance. The implementation may be updated to return orange
in both cases. If the original values are required, the LUMPDevice
may be used to get the original color index.
2020-08-10 11:29:48 +02:00
Laurens Valk 0c5457a5f2 api/parameters/Color: rename PURPLE to VIOLET
The correct term for hue = 270 is violet.
Purple is just magenta with a lower brightness value.
2020-08-10 11:29:32 +02:00
Laurens Valk 3488e1fb83 doc/pupdevices/UltrasonicSensor: document invalid
Document how invalid values are reported.
2020-07-10 12:32:52 +02:00
Laurens Valk 93da01c7ce api/pupdevices/ColorDistanceSensor: add hsv
The hsv and color_map methods are the same as for the SPIKE ColorSensor class, except for the surface kwarg.
2020-07-07 14:07:35 +02:00
Laurens Valk 55c4c86c23 api/_common: fix speaker file kwarg
In the implementation, the kwarg is called "file". Instead of fixing the implementation which is already released, we fix the docs.
2020-07-07 09:50:36 +02:00
Laurens Valk 82b16dc8de api/_common: fix DriveBase speed kwarg
In the implementation, the kwarg is called "speed". Instead of fixing the implementation which is already released, we fix the docs.
2020-07-07 09:50:30 +02:00
Laurens Valk 8078b6febb doc/_common/ColorLight: docstring clean up
This adds a (commented out) preview of the methods to the city hub light
2020-07-07 09:44:16 +02:00
Laurens Valk 8a43dc936a doc/signaltypes: add hue placeholder
We will have to add a helpful diagram, but having the placeholder allows us to link to it already.
2020-07-07 09:44:16 +02:00
Laurens Valk 7d1fbe9ce9 api/_common/Light: add reset to system behavior
This makes lights behave as they would if the user script did not use them at all.
2020-07-07 09:44:16 +02:00
Laurens Valk 38a1cf9712 api/_common/Light: drop repeat kwarg
The pattern will always repeat, for simplicity.
2020-07-07 09:44:16 +02:00
Laurens Valk 102039385a api/_common/ColorLight: add pattern
This adds the method equivalent to the recent addition of a single
color light. The only difference is that now a color is returned instead
of a single brightness. The provided color or HSV tuple will be stored
as RGB samples internally, as is already done for pbio light patterns.

In the simplest blinking form this could be:

hub.light.pattern(lambda t: Color.RED if t >= 1000 else None, 2000)

Or a fading, one-color sine:

def fade(time):
    v = sin(time/2000/pi)*50+50
    h = 360
    s = 100
    return (h, s, v)

hub.light.pattern(fade, 1000)
2020-07-07 09:44:16 +02:00
Laurens Valk e780a65007 api/_common/ColorLight: change rgb to hsv
This makes it much easier to have fine grained control
over colors and cycle through them easily (0--360).

This also makes it consistent with sensor APIs. Now you
can measure the color and plug it into this method.

We can make this change because none of
the implementations use this yet.

If we feel we miss out by dropping the RGB, it would be more fitting
to instead expose R, G, and B attributes which point to instances of
the Light class. However, this is using more memory for something that
isn't very useful.

We could also just provide generic color converters between rgb, hsv,
and perhaps hex html color strings, not tied to any particular light or
sensor.
2020-07-07 09:44:16 +02:00
Laurens Valk b8505ff218 api/_common/Light: introduce pattern
Currently, Pybricks has system patterns for builtin lights.
This adds a user method to set such a pattern.

For example, an indefinite sine pattern could be specified by

def fade(time):
    return sin(time/2000/pi)*50+50

hub.light.pattern(fade, 1000)

or a blinking pattern using

def blink(time):
    if time >= 1000:
        return 100
    else:
        return 0

hub.light.pattern(blink, 2000)

or briefly:

hub.light.pattern(lambda t: 100 if t >= 1000 else 0, 2000)

This combines the best of simplicity and efficiency: The user doesn't
have to calculate and provide an expensive list of floating points, but
provide a clean and adaptable method instead.
By sampling, we maintain a fixed length pattern which we can preallocate
for the hub lights, and the samples are calculated only once and the
callable may be garbage collected if given as lambda. Also, any
exceptions will be caught immediately during the one-off evaluation.
2020-07-07 09:44:16 +02:00
Laurens Valk 20fec6461a api/_common/LightGrid: make image more efficient
Usually, images are static, so they can be computed in advance instead of during runtime. This makes scripts smaller and much more memory efficient.

For example, now you can say:

HOUSE = 4685823

hub.grid.image(HOUSE)

since 4685823 =
```
0 0 1 0 0
0 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
```

We could also choose the binary format to allow for more generic screen sizes. If we allow a bit more space (2 words instead of 1), we could do 1 byte per row to allow screens up to 8x8. Right now, though, we choose 1 word < 31 bits which is a bit more efficient in MicroPython.

We can easily list numerous example in the docs or provide a simple visual calculator.

There is still a matrix method that takes a 2D matrix of intensities for full control during runtime, which is what the image() method was doing initially. This commit renames the old draft to matrix().
2020-07-07 09:44:16 +02:00
Laurens Valk d66e18b113 api/pupdevices: add TiltSensor
This class and its methods are subject to change when the complete
API for IMUs is introduced.
2020-07-01 13:33:36 +02:00
Laurens Valk 55fe666dac api/pupdevices: add InfraredSensor 2020-07-01 12:02:13 +02:00
Laurens Valk 80840396aa api/pupdevices: add Powered Up Light 2020-06-08 15:26:19 +02:00
Laurens Valk 1eac0972ac api/hubs: add CPlusHub 2020-06-05 15:56:04 +02:00
Laurens Valk ce993900d1 api/pupdevices: update illuminate argument
match the implementation and simplify description
2020-05-27 13:58:30 +02:00
Laurens Valk f604dd321e api/pupdevices/UltrasonicSensor: drop silent
Like its EV3 counterpart, this does not work reliably enough, so remove.
2020-05-27 13:58:30 +02:00
Laurens Valk e0ac54ec0a api/pupdevices/ForceSensor: add methods 2020-05-27 13:58:30 +02:00
Laurens Valk 8273c00881 api/pupdevices/UltrasonicSensor: add methods
This is identical to the EV3 Ultrasonic Sensor methods.
2020-05-27 13:58:30 +02:00
Laurens Valk 4da7b456bb api/pupdevices: initial color sensor hsv api
Provide a simple yet powerful way to calibrate the color() method.
2020-05-27 13:58:30 +02:00
Laurens Valk 7498751ee3 doc/pupdevices: add diagrams with light indices
Make this clear once and for all.
This order comes from the sensor itself.
2020-05-27 13:58:30 +02:00
Laurens Valk 2dd133d5e5 api/pupdevices: add ForceSensor
Initial class without any methods for the SPIKE Force Sensor
2020-05-27 13:58:30 +02:00
Laurens Valk e67c048b18 api/pupdevices: add UltrasonicSensor
Initial class without any methods for the SPIKE Ultrasonic Sensor
2020-05-27 13:58:30 +02:00
Laurens Valk 2d3e85f531 api/_common.LightArray: merge on and array method
Make it simpler with only one method to turn the lights on.
2020-05-27 13:58:30 +02:00
David Lechner daeac6005e api: media.ev3dev.Image.draw_circle: fix r arg
This removes the default value from the `r` parameter (this was probably copy/paste error from the `draw_box` method). The actual implementation does not have a default value.
2020-05-18 13:26:28 -05:00
Laurens Valk 4ca568079e doc/robotics: clarify wheel_diameter, axle_track
Add tips for practical experiments to validate the dimensions
2020-04-28 17:09:43 +02:00
Laurens Valk cdbe5b6fa3 doc/robotics: emphasize positive directions
- Move it to the class description, because it applies to all methods
- Use minimal and concise language, with only one definition per line, instead of having an elaborate paragraph.
2020-04-28 16:31:58 +02:00
Laurens Valk 350b90d967 doc/parameters: document stop types in table
Make more explicit how the stop types gradually add more resistance to motion.
2020-04-28 14:01:28 +02:00
Laurens Valk c6f7b514ec doc: remove ascii art for motor directions
We have actual graphics of motors with their default clockwise directions now, so refer to those instead.
2020-04-28 13:27:51 +02:00
Laurens Valk 9ff69a54fb api/tools: add append option to DataLog class 2020-04-27 17:18:37 +02:00
Laurens Valk 4de436e479 doc/motors: hide extra sections until ready
Avoid references to non-existing explanations.
2020-04-24 12:00:26 +02:00
Laurens Valk 55c5790a48 doc/nxtdevices: fix typo 2020-04-24 10:50:34 +02:00
Laurens Valk 6f8e3ba0ff doc/tools: improve datalog information
- Fix typo in example
- Explain how to upload a log file
- Show an example graph
2020-04-10 13:54:36 +02:00
David Lechner b5159a850a api: fix typo in Font parameter
script was missing a letter
2020-04-08 09:58:13 +02:00
Laurens Valk 32ab928aa8 doc/ev3devices/UltrasonicSensor: add freeze note
Simplify the text for silent mode, and add a note to say what to do if it stops working when the UART gets confused.
2020-04-07 13:41:04 +02:00
David Lechner 87c2b6857f api: Use leading _ to hide internals in intellisense
Intellisense in VS Code (both jedi and ms python language server) picks
up all imported names and suggests them with equal priority for
code completion. By adding a leading underscore, intellisense lists
these with a lower priority, so they don't get in the way.

Also rename from builtins to _common while we are touching this to
better reflect the intention of the module (it contains types shared
by multiple modules, not builtin types like int).
2020-03-25 20:24:32 +01:00
Laurens Valk 43c006d836 doc/builtins/Motor: return from run_until_stalled
The return argument was not documented.
2020-03-25 09:32:46 +01:00
Laurens Valk ada50328bb doc/pupdevices/Motor: fix reset_angle
The note about absolute angle support had accidentally ended up in the GyroSensor. It applies only to pupdevices.Motor.
2020-03-24 16:25:06 +01:00