I'm using the 13 December Stretch image on an ev3. I am trying to make the US sensor scan across 180 degrees, with the motor making 45 steps of 4° each, like a radar. I first tried the script below which uses run_to_rel_pos() but the end result was that the movement was not precise, despite the use of 'hold' rather than 'brake' which should help the precision. With the large motor, the angle was about 190° and with the medium motor it was about 150°. Since the idea is to then move the sensor quickly back to its original precision and repeat the scan, the errors would accumulate.
#!/usr/bin/env python3
from ev3dev.ev3 import *
from time import sleep
mB = LargeMotor('outB')
mB.stop_action = 'hold'
lcd = Screen()
positions = ''
for i in range(1,46):
mB.run_to_rel_pos(position_sp=4, speed_sp=200)
mB.wait_while('running')
positions = positions+' '+str(mB.position)
if i%7 == 6:
positions = positions+'\n'
sleep(0.4)
#lcd.clear() # not needed?
lcd.draw.text((0, 10), positions)
lcd.update()
sleep(10)
So then I tried using run_to_abs_pos() instead, and that worked much worse. My impression is that after every movement, the absolute position resets to zero, which means run_to_abs_pos() in fact works like run_to_rel_pos(), at least for me. Can anyone confirm? In these scripts, the position of the motor is recorded after each 4° motion and then all the positions are displayed after the motion ends.
#!/usr/bin/env python3
from ev3dev.ev3 import *
from time import sleep
mB = LargeMotor('outB')
mB.stop_action = 'hold'
lcd = Screen()
positions = ''
startpos = mB.position # will it always start at zero?
for i in range(1,46):
mB.run_to_abs_pos(position=startpos+i*4, speed_sp=200)
mB.wait_while('running')
positions = positions+' '+str(mB.position)
if i%7 == 6:
positions = positions+'\n'
sleep(0.4)
#lcd.clear() # not needed?
lcd.draw.text((0, 10), positions)
lcd.update()
sleep(10)
I'm using the 13 December Stretch image on an ev3. I am trying to make the US sensor scan across 180 degrees, with the motor making 45 steps of 4° each, like a radar. I first tried the script below which uses run_to_rel_pos() but the end result was that the movement was not precise, despite the use of 'hold' rather than 'brake' which should help the precision. With the large motor, the angle was about 190° and with the medium motor it was about 150°. Since the idea is to then move the sensor quickly back to its original precision and repeat the scan, the errors would accumulate.
So then I tried using run_to_abs_pos() instead, and that worked much worse. My impression is that after every movement, the absolute position resets to zero, which means run_to_abs_pos() in fact works like run_to_rel_pos(), at least for me. Can anyone confirm? In these scripts, the position of the motor is recorded after each 4° motion and then all the positions are displayed after the motion ends.