VLL Transmit for legOS
Doug Eaton posted
a message
to
lugnet.robotics
with a pointer to the
details of the VLL protocol
which he reverse-engineered.
As a legOS programming exercise I wrote a small library to transmit VLL
codes using the LED in the LEGO light sensor. You can
download the source which includes a diff to
kernel/dsensor.c
required to enable the sensor access
that vll.c
needs. You can add VLL to the kernel if you
like, or just compile it into your own applications.
The distribution includes a legOS.srec
and legOS.lds
which includes the required patch as well as VLL built in. To use it:
#include <dsensor.h>
#include "vll.h"
yourfunc()
{
/* take over light sensor on input 1 */
vll_init(&SENSOR_1);
vll_send(VLL_MS_FWD);
...
vll_stop();
}
Features
- It works with my MicroScout!
- It probably works with the Code Pilot (but I don't have one --
missed the S&H special)
- I transcribed the VLL codes from the Scout SDK into the header file
for your convenience.
- You can send codes back to back in a tight loop and the library will ensure that they are padded.
Limitations
There are a few aspects which could work better:
- The light sensor LED is much dimmer than the Scout's.
If you point a Scout directly at
the MicroScout it can communicate from several inches away. The small
LED on the light sensor only has a useful VLL range of about one inch (3cm).
- The LED is much slower than the Scout's. It can't transition from
off to on as quickly (or the interface electronics buffer the signal
too much). The RCX can transmit one VLL code in about 0.4s. The Scout
is at least 3 times faster. This means that the RCX can't keep the
MicroScout's motor turning constantly in immediate mode.
- You can't use the light sensor as a light sensor simultaneously. This is
due to my hack to
dsensor.c
which gives the VLL library full
control over the port being used. The interrupt handler can't drop the
output voltage momentarily to read the sensor. It's possible that there
is a better way to patch the kernel to support this, or I may be able to
poll the sensor in a VLL library routine. You can init and stop the VLL
port in a loop if you have to, but you'll have to wait for the light sensor
readings to settle each time.
- You can't receive VLL. Well, that's not so bad, since it's not even
clear that the Scout can do that!
- You can only have on VLL output port at a time. This seemed like
plenty to me.
Future Work
Okay, I admit, I'll probably never use this for anything. On the other
hand, if you are big into MicroScout programming, or you have a Code Pilot,
it might be useful to have an RCX app that lets you build small programs
on the console of the RCX.
Disclaimer
If this fries your light sensor, I take no responsibility! You are trying
this at your own risk.
Other VLL Implementations
About a day after I announced this code for legOS,
Jin Sato
announced a
VLL library
for NQC written by
Shigeru Makino. They have code to
use the light sensor as an output device and also support using a LEGO lamp
connected to a motor output.
Due to the limitations of NQC their transmit rate appears to be about one
third that of the legOS version.