Giter VIP home page Giter VIP logo

pycreate2's Introduction

image

pyCreate2

Actions Status GitHub PyPI - Python Version PyPI PyPI - Downloads

A python library for controlling the iRobot Create 2. This was used in ECE 387 Introduction to Robotics class I taught at the US Air Force Academy.

  • video: robot could only follow the black tap road and couldn't run into anything. If anything got in the way, it had to naviage around it to its final destination
  • video: robot pet, follow the pink ball
  • video: robot pet, follow the pink ball

Install

pip

The recommended way to install this library is:

pip install pycreate2

Development

If you wish to develop and submit git-pulls, you can do:

git clone https://github.com/walchko/pycreate2
cd pycreate2
poetry install
poetry run pytest -v

Use

There are multiple ways to command the Create to move, here are some examples:

from  pycreate2 import Create2
import time

# Create a Create2.
port = "/dev/serial"  # where is your serial port?
bot = Create2(port)

# Start the Create 2
bot.start()

# Put the Create2 into 'safe' mode so we can drive it
# This will still provide some protection
bot.safe()

# You are responsible for handling issues, no protection/safety in
# this mode ... becareful
bot.full()

# directly set the motor speeds ... move forward
bot.drive_direct(100, 100)
time.sleep(2)

# turn in place
bot.drive_direct(200,-200)  # inputs for motors are +/- 500 max
time.sleep(2)

# Stop the bot
bot.drive_stop()

# query some sensors
sensors = bot.get_sensors()  # returns all data
print(sensors.light_bumper_left)

# Close the connection
# bot.close()

More examples are found in the examples folder.

Documents

Additional notes and documents are in the docs folder.

Modes

image

The different modes (OFF, PASSIVE, SAFE, and FULL) can be switched between by calling different commands.

  • OFF: The robot is off and can charge, it will accept no commands
  • PASSIVE: The robot is in standbye and can charge. It will send sensor packets, but will not move
  • SAFE: The robot will not charge, but you full control over it with a few exceptions. If the cliff sensors or wheel drop sensors are triggered, the robot goes back to PASSIVE mode.
  • FULL: The robot will not charge and you have full control. You are responsible to handle any response due to cliff, wheel drop or any other sensors.

Sensor Data

Sensor data is returned as a namedtuple from collections. The information can be accessed as either:

sensors = bot.get_sensors()
sensors.wall == sensors[1]  # True
Sensor Range Index
bumps_wheeldrops [0-15] 0
wall [0-1] 1
cliff_left [0-1] 2
cliff_front_left [0-1] 3
cliff_front_right [0-1] 4
cliff_right [0-1] 5
virtual_wall [0-1] 6
overcurrents [0-29] 7
dirt_detect [0-255] 8
ir_opcode [0-255] 9
buttons [0-255] 10
distance [-322768-32767] 11
angle [-322768-32767] 12
charger_state [0-6] 13
voltage [0-65535] 14
current [-322768-32767] 15
temperature [-128-127] 16
battery_charge [0-65535] 17
battery_capacity [0-65535] 18
wall_signal [0-1023] 19
cliff_left_signal [0-4095] 20
cliff_front_left_signal [0-4095] 21
cliff_front_right_signal [0-4095] 22
cliff_right_signal [0-4095] 23
charger_available [0-3] 24
open_interface_mode [0-3] 25
song_number [0-4] 26
song_playing [0-1] 27
oi_stream_num_packets [0-108] 28
velocity [-500-500] 29
radius [-322768-32767] 30
velocity_right [-500-500] 31
velocity_left [-500-500] 32
encoder_counts_left [-322768-32767] 33
encoder_counts_right [-322768-32767] 34
light_bumper [0-127] 35
light_bumper_left [0-4095] 36
light_bumper_front_left [0-4095] 37
light_bumper_center_left [0-4095] 38
light_bumper_center_right [0-4095] 39
light_bumper_front_right [0-4095] 40
light_bumper_right [0-4095] 41
ir_opcode_left [0-255] 42
ir_opcode_right [0-255] 43
left_motor_current [-322768-32767] 44
right_motor_current [-322768-32767] 45
main_brush_current [-322768-32767] 46
side_brush_current [-322768-32767] 47
statis [0-3] 48

Change Log

2021-02-22 0.8.1 Cleaned up code
2020-02-16 0.8.0 Simplified interface and bug fixes
2020-02-16 0.7.7 Fixed typo with poetry
2020-02-16 0.7.6 Fixed typo erro in bin
2020-02-16 0.7.5 Switched to toml and poetry
2019-06-30 0.7.4 Midi sounds working
2017-08-26 0.7.3 code clean up and doc updates
2017-08-26 0.7.2 updates and fixes
2017-05-26 0.5.0 init and published to pypi

The MIT License

Copyright (c) 2007 Damon Kohler

Copyright (c) 2015 Jonathan Le Roux (Modifications for Create 2)

Copyright (c) 2015 Brandon Pomeroy

Copyright (c) 2017 Kevin Walchko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pycreate2's People

Contributors

andrewda avatar randomdemon avatar walchko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pycreate2's Issues

Implementation details

I see you used some of my python implementation of the iRobot Open Interface spec in your library, but there is quite a bit of functionality from the spec you left out. I separated my implementation into a complete implementation of the OI and a Create2 class that uses the OI implementation to implement the robot's functionality with the intent that the OI implementation may be used to create robot classes with as much or as little of the OI functionality as you needed. It would seem it wasn't quite successful as you only took some pieces of it. Would you share your use case(s) for the library with me or suggest ways my implementation would have better met your needs?

songs don't aways play

The create is finicky with songs. Sometimes they work, sometimes they don't. It could be a bug in my 2007 firmware that came with my new 2017 Create 2.

Several errors

I am using the python package to read out the light bumper values of the icreate 2 robot. When I do so, I get sensible values for a few minutes. However, after a few minutes (this is variable), the values become nonsense. The values become much larger than the max of 4095 stated in the manual.

We have 8 of these robots, and I can confirm this is not an issue with a particular robot. I have not systematically tested every robot, but I have seen this on several robots.

Therefore, I think that either firmware of the robot or the python code has bugs. In fact, I have noticed other problems with the robots that might be due to the same underlying problem.

  1. The move command and turn command sometimes fail with the robot only moving or turning a few millimetres.

  2. Sometimes I lose control of the robot with a python error message saying that only 0 bytes of sensor data were read (and 80 were expected).

Any way I can contribute?

Hey,

This library was a lifesaver in high school while programming my Create2. Now that I'm more acquainted with programming, I wanted to see if I could meaningfully contribute to this library. Any functions that you had trouble with? Any documentation that needs to be included?

Not installing latest package thru pip

When I do pip install pycreate2 it seems to install older package and not the newer one that has fixes to MIDI tones.

Also, there is a missing comma line 50 in setup.py when installing from cloned copy and the missing README.rst file. Fixing these two issues will help install from the cloned copy.

'is_open' deprecated in pySerial

Currently does not work with newest version of Python and updated modules. All ser.is_open should be replaced with ser.isOpen() in createSerial.py

small bug in run example

Hi,
thanks for creating this library!
I just found a small bug in the runExample.py.
it uses
bot.direct_drive(lft, rht)
but the correct command is
bot.drive_direct(lft, rht)

HC

Command to check bumpers?

First and foremost thanks for creating this library! I've been looking for such a long time for a quality library to use with the robot.

With that said, did you end up writing a command to check the bumper state? I'm trying to program the robot to let out an "angry" beep and write to an LCD when it bumps into something. If this isn't programmed in already, do you know how I would go about that? I was trying to mess with the library myself however I just find myself more and more confused lol

OI mode command doesn't work

The robot seems to never respond to the mode command (packet 35). I can't figure out why. This appears to be a firmware bug with the Create 2. The reset command gives me this firmware info:

('Firmware Version:', 'bl-start\r\nSTR730\r\nbootloader id: #x47186549 82ECCFFF\r\nbootloader info rev: #xF000\r\nbootloader rev: #x0001\r\n2007-05-14-1715-L \r')

Basically my 2017 Create 2 has 2007 firmware ... yeah!!!

Sensors commands and storing the information

The way the library handles sensor packets seems overly complex and long ... there has to be a better way.

Maybe just have the packet decoders and leave it up to the programmer to figure out a way (that works nicely for them) to handle the sensor info?

turn_angle function not stopping

sorry to spam you with issues :)

I thought I'd let you know that the turn_angle() function sets the robot rotating. But it never stops. I think you forgot to set the robot speed to zero at the end?

Should the last line of this function read

 self.robot.drive_direct(0, 0)

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.