itdaniher / WeDoMore

A Python Library & Reverse Engineering for the WeDo Kit.
GNU General Public License v2.0
36 stars 18 forks source link

Motor can give ID of 240, add lights/servo #7

Closed cpseager closed 7 years ago

cpseager commented 9 years ago

Hopefully this info is useful:

https://github.com/itdaniher/WeDoMore/blob/master/wedo/__init__.py#L22

Add 240 as a valid motor ID value, as the stationary motor can also give out this ID value and so the motor identification can presently be a little unreliable at times.

Additionally if you also add in these values as valid motor values 99, 100, 101, 102 (servo, 88004) 203, 204 (lights, 8870)

these 2 power functions output devices will also start working (they are controlled as if they are motors so there is nothing else to do apart from make their ID a value valid)

For interest here is the complete set with the upper boundary value (and value of the internal pull-down resistor used to generate the iD). Note that many of these parts were never released by Lego!

var WEDO_TYPE_SHORTLO   =   9 ; // (short to 0V, 0) motor active braking also gives value <5
var WEDO_TYPE_BEND  =  27 ; // (1k5, 16-17)
var WEDO_TYPE_TILT  =  47 ; // (3k9, 38-39) 
var WEDO_TYPE_FUTURE=  67 ; // (6k8, 58-59)
var WEDO_TYPE_RAW   = 82 ; // (10k, 77-78)
var WEDO_TYPE_TOUCH =  92 ; // (12k, 86-87) 
var WEDO_TYPE_SERVO = 109 ; // (15k, 99-102)
var WEDO_TYPE_SOUND = 131 ; // (22k, 120-121)
var WEDO_TYPE_TEMP  = 152 ; // (33k, 143-144)
var WEDO_TYPE_LIGHT = 169 ; // (47k, 161-162) 
var WEDO_TYPE_MOTION    = 190 ; // (68k, 176-179) 
var WEDO_TYPE_LIGHTBRICK= 207 ; // (150k, 203-204)
var WEDO_TYPE_22    = 224 ; // (220k, 210-211)
var WEDO_TYPE_OPEN  = 233 ; // (228-231) no i/o device is connected
var WEDO_TYPE_MOTOR = 246 ; // (short via motor coil to sensor pd, 238-240) 
var WEDO_TYPE_SHORTHI   = 255 ; // (short to V+, 255)
cpseager commented 9 years ago

Also, in case anyone can make some use of this: supplyVoltage = (rawdata[1] * 49) / 1000;

itdaniher commented 9 years ago

Wow, thanks!

AlanJAS commented 9 years ago

We have similar problem with sensors. We add 40 for tilt and 180 for distance.

https://github.com/AlanJAS/WeDoMore/blob/master/wedo/__init__.py

This change can broke some identifications?

cpseager commented 9 years ago

I think the way Lego designed these values was to allow a a large tolerance, so for instance a tilt sensor could actually be any value between the boundaries e.g.

 if (id < WEDO_TYPE_SHORTLO)
    \\ is a short
 else if (id < WEDO_TYPE_BEND)
    \\ bend sensor
 else if (id < WEDO_TYPE_TILT)
    \\ tilt sensor

etc.

So for a tilt sensor values of 38,39, 40 are all well within this range (27 to 46)

itdaniher commented 7 years ago

If anyone has enough hardware to test these numbers and is interested in working on a PR expanding support, let me know!