[Snek] Is EV3 port of Snek a good idea?
keithp at keithp.com
Sat Feb 8 11:54:00 PST 2020
"Mikhail Gusarov" <dottedmag at dottedmag.net> writes:
> I thought a bit about it, and here's the mapping — any ideas about
> EV3 ports: 1-4 sensors, A-D actuators. `talkto` sets the current port.
So, talkto(A) and read(1)? Seems reasonable.
> # Tacho motor
> - `setpower` sets the speed, 0..1 (XXX max speed is 3 rotations per
> second - should it be 0..3?)
Hrm. I'd *probably use 0..1, but I can definitely see the benefit of
exposing RPS directly. That'd be pretty cool.
> - `setleft` / `setright` as usual
> - `on` / `off` as usual
> - `onfor` as usual
> - `read` reads the current speed
Hrm. That's an interesting idea. With the Arduino boards, because pins
can be used for either input or output, doing a read() switches the mode
of the pin. These boards don't work that way.
> XXX Tacho motors know their position and can rotate to reach position X
> XXX and to increase position by X. How to expose it?
I'd suggest using read() to report the current position.
With Power Functions servos, we use 'setpower()' to set the amount of
rotation relative to center and setleft(), setright() to select the
direction of rotation. I didn't have to do anything magic to make this
happen; the servos just worked that way.
Maybe expose a function which selects absolute position mode and use
setpower to select the position? Or just expose a new function,
setposition, which does that? I could add setposition to other Snek
ports and have it use -1 .. 1 to set position relative to the center
location for power functions motors?
> # Push button
> - `read` as usual: 0/1
> # Distance sensor
> - `read` as usual: 0..n centimetres, `inf` if unable to sense anything
Oh, very cool.
> # Light sensor
> This sensor has 4 modes.
> - XXX `setmode(COLOR)`? `setpower(COLOR)`?
Probably not setpower, that's confusing. All of the current functions
take a single value as that avoids any question about order, so
maybe separate functions? I think there's a parallel here with the
pull-up/pull-down configuration functions, perhaps those can be a guide:
pullup(1) Enable pull-up, switch to digital mode
pulldown(1) Enable pull-down, switch to digital mode
pullnone(1) Disable pull-up/pull-down, switch to analog mode
> Or use `read(A_COLOR)`? But mode needs to be set before read, or the
> won't have time to happen after mode switch.
Right, plus read() takes a port name parameter, so you'd have a
different function or some weird use of tuples to make that work.
> - `read` as usual, results depend on the current mode:
> - reflected strength: strength of sensor's LED reflected from object,
> - ambient strength: strength of ambient light, 0..1
> - color: "none" / "black" / "blue" / "green" / "yellow" / "red" /
> "white" / "brown"
> - RGB: (0, 0, 0) .. (1, 1, 1)
> # Gyroscope
> XXX Not even started on this yet.
I assume that's measuring rotation rates? Should use the same units as
the motor speed setting
This looks really cool!
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 832 bytes
Desc: not available
More information about the Snek