Help on module create: NAME create FILE /usr/local/lib/python2.7/dist-packages/create.py DESCRIPTION # create.py # # Python interface for the iRobot Create # # Zach Dodds dodds@cs.hmc.edu # updated for SIGCSE 3/9/07 # CLASSES Create RoombaRobot SensorFrame class Create | the Create class is an abstraction of the iRobot Create's | SCI interface, including communication and a bit | of processing of the strings passed back and forth | | when you create an object of type Create, the code | will try to open a connection to it - so, it will fail | if it's not attached! | | Methods defined here: | | 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) | | Stop(self) | Stop calls Go(0,0) | | __init__(self, PORT, startingMode=2) | the constructor which tries to open the | connection to the robot at port PORT | | 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 | | demo(self, demoNumber=-1) | runs one of the built-in demos for Create | if demoNumber is | or | -1 stop current demo | 0 wander the surrounding area | 1 wander and dock, when the docking station is seen | 2 wander a more local area | 3 wander to a wall and then follow along it | 4 figure 8 | 5 "wimp" demo: when pushed, move forward | when bumped, move back and away | 6 home: will home in on a virtual wall, as | long as the back and sides of the IR receiver | are covered with tape | 7 tag: homes in on sequential virtual walls | 8 pachelbel: plays the first few notes of the canon in D | 9 banjo: plays chord notes according to its cliff sensors | chord key is selected via the bumper | | drive(self, roomba_mm_sec, roomba_radius_mm, turn_dir='CCW') | implements the drive command as specified | the turn_dir should be either 'CW' or 'CCW' for | clockwise or counterclockwise - this is only | used if roomba_radius_mm == 0 (or rounds down to 0) | other drive-related calls are available | | getData(self) | for class | | getMode(self) | returns one of OFF_MODE, PASSIVE_MODE, SAFE_MODE, FULL_MODE | | getNextDataFrame(self) | This function then gets back ALL of | the sensor data and organizes it into the sensor | dictionary, sensord. | | getPose(self, dist='cm', angle='deg') | getPose returns the current estimate of the | robot's global pose | dist may be 'cm' or 'mm' | angle may be 'deg' or 'rad' | | getRawSensorDataAsList(self, listofsensors) | gets the chosen sensors | and returns the raw bytes, as a string | needs to be converted to integers... | | getRawSensorFrameAsList(self, packetnumber) | gets back a raw string of sensor data | which then can be used to create a SensorFrame | | 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) | | integrateNextOdometricStepCreate(self, distance, rawAngle) | integrateNextOdometricStep adds the reported inputs | distance in mm | rawAngle in degrees | to the estimate of the robot's global pose | | integrateNextOdometricStepRoomba(self, distance, rawAngle) | integrateNextOdometricStep adds the reported inputs | distance in mm | rawAngle in mm | to the estimate of the robot's global pose | | interpretSensorString(self, r) | This returns a sensorFrame object with its fields | filled in from the raw sensor return string, r, which | has to be the full 3-packet (26-byte) string. | | r is obtained by writing [142][0] to the serial port. | | playNote(self, noteNumber, duration, songNumber=0) | plays a single note as a song (at songNumber) | duration is in 64ths of a second (1-255) | the note number chart is on page 12 of the open interface manual | | playSong(self, list_of_notes) | The input to playSong should be specified as a list | of pairs of [ note_number, note_duration ] format. Thus, | r.playSong( [(60,8),(64,8),(67,8),(72,8)] ) plays a quick C chord. | | playSongNumber(self, songNumber) | plays song songNumber | | printSensors(self, d=None) | convenience function to show sensed data in d | if d is None, the current self.sensord is used instead | | readSensorList(self, sensor_data_list, r) | this returns the latest values from the particular | sensors requested in the listofvalues | | resetPose(self) | resetPose simply sets the internal odometry to 0,0,0 | | seekDock(self) | sends the force-seeking-dock signal | | sensors(self, list_of_sensors_to_poll=6) | this function updates the robot's currently maintained | state of its robot sensors for those sensors requested | If none are requested, then all of the sensors are updated | (which takes a bit more time...) | | setBaudRate(self, baudrate=10) | sets the communications rate to the desired value | | setLEDs(self, power_color, power_intensity, play, advance) | The setLEDs method sets each of the three LEDs, from left to right: | the power LED, the play LED, and the status LED. | The power LED at the left can display colors from green (0) to red (255) | and its intensity can be specified, as well. Hence, power_color and | power_intensity are values from 0 to 255. The other two LED inputs | should either be 0 (off) or 1 (on). | | setNextDataFrame(self) | This function _asks_ the robot to collect ALL of | the sensor data into the next packet to send back. | | setPose(self, x, y, th, dist='cm', angle='deg') | setPose sets the internal odometry to the input values | x: global x in mm | y: global y in mm | th: global th in radians | dist: 'cm' or 'mm' for x and y | angle: 'deg' or 'rad' for th | | setSong(self, songNumber, songDataList) | this stores a song to roomba's memory to play later | with the playSong command | | songNumber must be between 0 and 15 (inclusive) | songDataList is a list of (note, duration) pairs (up to 16) | note is the midi note number, from 31 to 127 | (outside this range, the note is a rest) | duration is from 0 to 255 in 1/64ths of a second | | setWheelVelocities(self, left_cm_sec, right_cm_sec) | sends velocities of each wheel independently | left_cm_sec: left wheel velocity in cm/sec (capped at +- 50) | right_cm_sec: right wheel velocity in cm/sec (capped at +- 50) | | start(self) | changes from OFF_MODE to PASSIVE_MODE | | stop(self) | stop calls go(0,0) | | toFullMode(self) | changes the state to FULL_MODE | | toSafeMode(self) | changes the state (from PASSIVE_MODE or FULL_MODE) | to SAFE_MODE | | turnOnRooToothPower(self) | the RooTooth Bluetooth radio has its PIO pin 6 | attached to the RTS serial line for waking the | roomba up... class RoombaRobot | this class contains a Roomba object to handle all of the | communications, but this class actually starts to reason | about the robot, e.g., where it is right now... | | Methods defined here: | | GetPose(self) | cheats by providing the internal pose... | | GetPoseReal(self) | GetPose updates the pose and returns it | | Go(self, cm_per_sec, deg_per_sec) | Go sets the velocity in cm/sec and deg/sec | | SetCollisions(self, doWeCrashIntoWalls) | sets the simulator to use or ignore walls | | SetPose(self, x, y, thr) | set's the robot's global pose to x, y, thr | | __init__(self, PORT, mapfilename=None) | the constructor creates the robot object | and tracks its position class SensorFrame | the sensorFrame class is really a struct whose | fields are filled in by sensorStatus | | Methods defined here: | | __init__(self) | constructor -- set all fields to 0 | | see interpretSensorString for details | on all of these fields | | __str__(self) | returns a string with the information | from this SensorFrame | | toBinaryString(self) | this converts the calling SensorFrame into a 26-byte | string of the format the roomba sends back FUNCTIONS bitOfByte(bit, byte) returns a 0 or 1: the value of the 'bit' of 'byte' bytesOfR(r) for looking at the raw bytes of a sensor reply, r fromBinary(s) s is a string of 0's and 1's modeStr(mode) prints a string representing the input SCI mode poseDeltaFromVelRadSec(vel_mm_sec, ROC, sec) returns the pose change (dx,dy,dthr) in (mm,mm,radians) undergone by a differential-drive robot with a wheelspan of 258mm that is traveling with a "velocity" of vel_mm_sec, along a radius of ROC_mm, for sec seconds NOTE that the pose change is represented in the canonical "robot-centric" coordinate system: Hooray for ASCII art! | +x aligned to robot's heading | ^ | ^ | | | +y <---WL--+--WR--- -y perp to robot's heading | | DELTA = 1/2 distance from WL to WR | -x vel_mm_sec is the average of the velocities of WL and WR it is positive when the robot is moving forward the center of the robot's circular arc is at (0,ROC) positive ROC => turning to the left negative ROC => turning to the right Special cases: ROC == 1 => counterclockwise ROC == -1 => clockwise ROC == 32768 => straight toBinary(val, numbits) prints numbits digits of val in binary toTwosComplement2Bytes(value) returns two bytes (ints) in high, low order whose bits form the input value when interpreted in two's complement twosComplementInt1byte(byte) returns an int of the same value of the input int (a byte), but interpreted in two's complement the output range should be -128 to 127 twosComplementInt2bytes(highByte, lowByte) returns an int which has the same value as the twosComplement value stored in the two bytes passed in the output range should be -32768 to 32767 chars or ints can be input, both will be truncated to 8 bits