Giter Club home page Giter Club logo

pycreate's Introduction

What is Create

iRobot Create is a mobile robot platform that is preassembled and ready to use. iRobot provides a documented open serial interface called, "iRobot Create Open Interface." Pycreate uses a Python implementation of this interface from Rose-Hulman.

What is this Fork?

A backport of pyCreate to be Python 2.7 compatible-- very much still under development. Surely this is offensive to some, but Python 2.7 is still used by many.

Requirements

  • Python >= 2.6 && Python <= 3.x:

    https://www.python.org/download/releases/2.7/
    
  • PySerial >= 1.0:

    http://pythonhosted.org/pyserial/pyserial.html#installation
    (2.7 recommended: https://pypi.python.org/pypi/pyserial/2.7)
    
  • TkInter:

    https://www.python.org/download/mac/tcltk/
    

Resouces

Hardware

Choose any of these four options to get started:

  1. Teather: Create and computer directly connected with wire. (serial 9pin to usb or rs232)
  2. Teather and wireless: Above setup with an additional computer and 802.11 network
  3. Wireless: Create and computer wireless connection via bluetooth network
  4. Simulator: Computer with create software environment and without the create hardware

After choosing an above option, get started (see Resources for Simulator):

  1. Power up robot on floor and verify green led
  2. Make physical and/or wireless connection between robot and computer
  3. Determine serial port name used to connect to robot
  4. Open serial port between robot and computer with python

Software

Copy this folder into your project folder and start python from the project folder --e.g., if you are working in /home/user/myRobot, copy into /home/user/myRobot/pyCreate Download the ZIP into that folder or use git clone from the command line

$ git clone git://github.com/mjocean/pycreate

We need to know the OS assigned serial port name given to robot hardware. Linux/OSX:

$ ls /dev/tty <tab>  # determine the correct serial port to robot hardware
/dev/ttyUSB0         # my serial port name associated with create, yours may differ
Windows::
Launch the Arduino development GUI and check the COM port number, as shown here: https://www.arduino.cc/en/uploads/Guide/SelectingUno.png

Take a note of the value above, either /dev/ttyXXXX or COM#

Any OS:: Launch Python:
$ python # start python
From Python, import the create library:
>>> from pyCreate import create    # load the create module into memory
OSX users type::
>>> r = create.Create('/dev/ttyUSB0')  # open serial connection, assign object to r
Windows users::
>>> r = create.Create('COM4')  # open serial connection for windows

Sense:

>>> r.getSensor('ANGLE')  # read the current value of angle sensor from robot
107
>>> r.getSensor('DISTANCE') # read the current value of distance sensor from robot
-271

Light:

>>> r.setLEDs(0, 255, 1, 1)   # Green, Bright, Green, Green
>>> r.setLEDs(255, 255, 0, 0) # Red, Bright, Off, Off

Music:

>>> r.playSong( [(60,8),(64,8),(67,8),(72,8)] ) # a C chord

Move:

>>> r.go(-5)         # move at -5 cm/second, backwards
>>> r.stop()         # stop robot motion
>>> r.go(0, 10)      # 0 cm/sec translational velocity and 10 deg/sec rotational
>>> r.shutdown()     # stop and close the connection to the robot

Graphic:

>>> import graphics  # load the graphics module into memory
>>> win = graphics.GraphWin("Me", 100, 100) # open a 100x100 window
>>> win.close()      # close window
>>> <CTRL> d         # close python

Appendix

  • sense.py:

    • a function to gather sensors key, value pairs. Open a file and write the sensor data to the file and stdout one sensor data point per line.
  • light.py:

    • Includes a function kitt() that takes two parameters: the robot and num_repeats. Toggles the play and advance lights on/off in sequence repeated num_repeats times and has a different color on the power led.
  • dance.py:

    • Includes a function dance(). First light up, then play a distinctive sound, continue with a robot dance, finally repeat zero or more times.
  • via.py:

    • Drive the robot through an environment via points stored in a file. Use feedback from the encoders to drive a certain distance. An encoder is a mechanical device attached the robot's wheels to measure how far it has traveled.

      • Prompt the user for the file name and open the file with that name.
      • Read each line of the file. Each line will contain 4 values: turn_angle_in_deg, turn_speed, fwd_distance_in_cm, fwd_velocity.
      • For each line, turn robot based upon the turn angle and speed, then drive the robot forward based upon the forward distance and velocity.
  • wander.py:

    • Includes a function wander() that takes three parameters: the robot, and linear and angular velocity. The parameters should be in the following order:

      1. robot
      2. [optional] Linear Velocity in cm/s, default = 15
      3. [optional] Angular Velocity in deg/s, default = 20
    • Select a random angle between or including -180 and 180 degrees (via randrange), turn the robot that much, select a random distance between 10 and 30 cm, and move the robot forward that much. Be sure that the sign on your velocities and distances are the same. Also make sure that when you calculate how long to sleep, you allow the answer to be a float. Repeat this random sequence of turn+drive 5 times or until its cliff sensor is triggered (i.e. pick it up) and use the go() method.

  • smart_wander.py:

    • smart_wander() should cause the robot to wander around randomly (turn then move, repeated 5 times), as it did for wander(), but also move away from any obstacles into which it bumps. Specifically:

      1. move for random angles between -180 and 180 degrees, and distances between 10 and 30 cm. Reminder: be sure that the sign on your velocities and distances are the same. Also, do NOT use wait_Angle() or wait_Distance() (or turnTo() or moveTo() which use them), since they monopolize the serial port, which you need for sensor data. Therefore, you will have to use go() and stop() and calculate how long to sleep manually.

      2. If the robot runs straight into an obstacle (left and right bumpers sensed), then back up. Choose a sensible distance to back up: enough to get away from the obstacle, but not enough to back up into another obstacle. You may then go on to the next random turn and move (in other words, you don't have to try to complete the move that was blocked).

      3. If the robot runs into an obstacle at an angle such that only the left bumper senses it, then backup and turn clockwise (for your sensible choice of an angle). Then execute the next random turn and move.

      4. If the robot runs into an obstacle at an angle such that only the right bumper senses it, then backup and turn counter-clockwise (for your sensible choice of an angle). Then execute the next random turn and move.

  • cliff_sensors.py:

    • a function cliff_sensors() requires you to read four sensors and control two LED actuators:

      • The front left and front right cliff sensors as an analog values
      • The left and right bumpers as digital values (to determine the program end)
      • The Play and Advance LEDs

      Read the front left and front right cliff sensors while moving a black line below the sensors. Print out the black line PDF and use it for testing. The location of the black line controls the state of the Play and Advance LEDs.

      When the black line is below the front right cliff sensor the Play LED should be off. When the black line is below the left cliff sensor the Advance LED should be off. When the black line is not below the sensor the corresponding LED should be on.

      In addition to the LEDs, print out the value of the analog sensor to the computer display using print. In fact you should probably do the printing part first! Since you will need to know where to set the threshold value to decide when the black line is present or absent for the LEDs, you will need to know the range of light and dark values. The values of both sensors should print to the screen every 0.1 seconds using a well formatted print message.

      For my program it was simply: Cliff Sensors FL = 80 FR = 720. This line was taken while the black line was below the Front Left Cliff Sensor. Make note of what the white and black values are for your program for each sensor. The printing of the cliff sensor values and controlling of the LEDs should continue inside a while loop until the user pushes either the left or right bumper. When a bumper press is observed the program should shutdown the robot and print a Goodbye message to the screen.

  • sense.py:

    • a function to print out sensors key, value pairs.

pycreate's People

Contributors

gkoloventzos avatar mgobryan avatar mjocean avatar tylerlemieux avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.