-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Functions Ed.ReadDistance() and Ed.SetDistance() should work with "ticks" as it is described in the documentation (https://meetedison.com/content/EdPy-app-documentation-guide.pdf).
Current implementation in EdPy converts ticks to CM or INCH. What conversion is used depends on value of Ed.DistanceUnits. Please, don't do conversion!
Other idea. What about extending Ed.DistanceUnits with value "TICK"? This will allow to work with motors at low level, with ticks. To pass TICKS as parameter to function Drive(), DriveLeftMotor(), etc
Documentation defines that one tick is 1.25mm. That is nice theory. In practice, there is no easy relation between distance and ticks, 1.25 is just an approximation (and that value is wrong from my point of view).
Some real data, relation between ticks and distance passed by robot at speed SPEED_5:
20 ticks => 44mm => 1 tick ~ 2.200 mm
40 ticks => 66mm => 1 tick ~1.650 mm
60 ticks => 94mm => 1 tick ~ 1.567 mm
80 ticks => 114mm => 1 tick ~ 1.425 mm
Distance depends on motor speed:
60 ticks @ SPEED_1 => 84mm => 1 tick ~ 1.400 mm
60 ticks @ SPEED_5 => 93mm => 1 tick ~ 1.550 mm
60 ticks @ SPEED_10 => 105mm => 1 tick ~ 1.750 mm
It is probably problem of driver in firmware, how it controls motor and measures distance. Other problem is that when motor receives stop command, it still passes few millimeters before it really stops, when motor runs faster it needs longer distance to stop. In my simple test I measured value of 1 tick between 1.400 mm and 2.200 mm... This is more than value in documentation that is 1.25mm
This is a demo program I used to measure relation between distance and ticks:
#-------------Setup----------------
import Ed
Ed.EdisonVersion = Ed.V2
Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM
#--------Your code below-----------
def ReadDistance_TICK(which):
if ((which & 0x01) == Ed.MOTOR_LEFT):
which = Ed.ReadModuleRegister16Bit(Ed.MODULE_LEFT_MOTOR, Ed.REG_MOTOR_DISTANCE_16)
else:
which = Ed.ReadModuleRegister16Bit(Ed.MODULE_RIGHT_MOTOR, Ed.REG_MOTOR_DISTANCE_16)
return which
def SetDistance_TICK(which, distance):
if (distance > 0):
if ((which & 0x01) == Ed.MOTOR_LEFT):
Ed.WriteModuleRegister16Bit(Ed.MODULE_LEFT_MOTOR, Ed.REG_MOTOR_DISTANCE_16, distance)
# Turn on the 5th bit, which turns on distance checking
Ed.SetModuleRegisterBit(Ed.MODULE_LEFT_MOTOR, Ed.REG_MOTOR_CONTROL_8, 5)
else:
Ed.WriteModuleRegister16Bit(Ed.MODULE_RIGHT_MOTOR, Ed.REG_MOTOR_DISTANCE_16, distance)
# Turn on the 5th bit, which turns on distance checking
Ed.SetModuleRegisterBit(Ed.MODULE_RIGHT_MOTOR, Ed.REG_MOTOR_CONTROL_8, 5)
def Beep():
Ed.PlayBeep()
while Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED:
pass
def Drive(ticks, speed):
Ed.Drive(Ed.FORWARD, speed, Ed.DISTANCE_UNLIMITED)
SetDistance_TICK(Ed.MOTOR_LEFT, ticks)
SetDistance_TICK(Ed.MOTOR_RIGHT, ticks)
while ReadDistance_TICK(Ed.MOTOR_LEFT) > 0:
pass
# MAIN()
ticks = 40
speed = Ed.SPEED_5
Beep()
Ed.TimeWait(1, Ed.TIME_SECONDS)
Drive(ticks, speed)
Beep()
I have found these problems when I tried to drive Edison through a grid maze and I found that motor accuracy is a serious problem for Edison. Other toy robots on the market can handle grid maze much better, for example robot Botley or Code&Go Mouse.