text
stringlengths 1
93.6k
|
|---|
rightHighVal, rightLowVal = _toTwosComplement2Bytes( int(right_cm_sec*10) )
|
# send these bytes and set the stored velocities
|
self._write( DRIVEDIRECT )
|
self._write( chr(rightHighVal) )
|
self._write( chr(rightLowVal) )
|
self._write( chr(leftHighVal) )
|
self._write( chr(leftLowVal) )
|
def stop(self):
|
""" stop calls go(0,0) """
|
self.go(0,0)
|
# we've gotta update pose information
|
foo = self.sensors([POSE])
|
def motors ( self, side_brush = 0, main_brush = 0, vacuum = 0):
|
if (side_brush > 1):
|
side_brush = 1
|
elif (side_brush < -1):
|
side_brush = -1
|
if (main_brush > 1):
|
main_brush = 1
|
elif (main_brush < -1):
|
main_brush = -1
|
if (vacuum > 1):
|
vacuum = 1
|
elif (vacuum < 0):
|
vacuum = 0
|
byteToWrite = chr((16 if main_brush < 0 else 0) |
|
(8 if side_brush < 0 else 0) |
|
(4 if main_brush != 0 else 0) |
|
(2 if vacuum != 0 else 0) |
|
(1 if side_brush > 0 else 0))
|
self._write( MOTORS )
|
self._write( byteToWrite)
|
def go( self, cm_per_sec=0, deg_per_sec=0 ):
|
""" go(cmpsec, degpsec) sets the robot's velocity to
|
cmpsec centimeters per second
|
degpsec degrees per second
|
go() is equivalent to go(0,0)
|
"""
|
# need to convert to the roomba's drive parameters
|
#
|
# for now, just one or the other...
|
if cm_per_sec == 0:
|
# just handle rotation
|
# convert to radians
|
rad_per_sec = math.radians(deg_per_sec)
|
# make sure the direction is correct
|
if rad_per_sec >= 0: dirstr = 'CCW'
|
else: dirstr = 'CW'
|
# compute the velocity, given that the robot's
|
# radius is 258mm/2.0
|
vel_mm_sec = math.fabs(rad_per_sec) * (WHEEL_SPAN/2.0)
|
# send it off to the robot
|
self._drive( vel_mm_sec, 0, dirstr )
|
elif deg_per_sec == 0:
|
# just handle forward/backward translation
|
vel_mm_sec = 10.0*cm_per_sec
|
big_radius = 32767
|
# send it off to the robot
|
self._drive( vel_mm_sec, big_radius )
|
else:
|
# move in the appropriate arc
|
rad_per_sec = math.radians(deg_per_sec)
|
vel_mm_sec = 10.0*cm_per_sec
|
radius_mm = vel_mm_sec / rad_per_sec
|
# check for extremes
|
if radius_mm > 32767: radius_mm = 32767
|
if radius_mm < -32767: radius_mm = -32767
|
self._drive( vel_mm_sec, radius_mm )
|
return
|
def _start(self):
|
""" changes from OFF_MODE to PASSIVE_MODE """
|
self._write( START )
|
# they recommend 20 ms between mode-changing commands
|
time.sleep(0.25)
|
# change the mode we think we're in...
|
return
|
def close(self):
|
""" tries to shutdown the robot as kindly as possible, by
|
clearing any remaining odometric data
|
going to passive mode
|
closing the serial port
|
"""
|
# is there other clean up to be done?
|
# let's get rid of any lingering odometric data
|
# we don't call getSensorList, because we don't want to integrate the odometry...
|
self._getRawSensorDataAsList( [19,20] )
|
time.sleep(0.1)
|
self._start() # send Create back to passive mode
|
time.sleep(0.1)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.