Coder Social home page Coder Social logo

raspirobotboard3's Introduction

raspirobotboard3

Python library and design files for the RasPi Robot Board V3

If you were looking for the library for the version 2 board go to https://github.com/simonmonk/raspirobotboard2

Rusty Gereard has produced a Java library for the RRB3 - https://github.com/R-Gerard/RRB4J

Installing the Python Libraries

To install the library, issue the following commands

$ cd ~
$ git clone https://github.com/simonmonk/raspirobotboard3.git
$ cd raspirobotboard3/python
$ sudo python setup.py install

Attach the RRB3 to your Raspberry Pi. You do not need to attach batteries, motors or anything else to the RRB3 just yet. For now you can just power it through the Pi's normal USB power connector.

Lets run some tests from the Python Console now that everything is installed. We can experiment with the RRB3, even without any motors

Open a Python console (Python2 not 3) by typing the following into a Terminal window:

$ sudo python

Then, within the python console, type the following, one line at a time:

from rrb3 import *
rr = RRB3(9, 6)
rr.set_led1(1)
rr.set_led1(0)
rr.set_led2(1)
rr.set_led2(0)
rr.sw1_closed()

The last step should display the answer "False" because no switch is attached.

If you prefer, you can use True and False in place of 1 and 0 in the examples above.

Connect a Battery and Motors

The quickest way to use the RRB3 as a roving robot is to buy a robot chassis such as the Magician Chassis (available from many sources) or similar low-cost robot chassis kits from eBay. These kits come as a laser cut body, a pair of gearmotors, often a battery box and nuts and bolts to fix it all together.

Here is one such chassis. The first step is to bolt this all together. Note that these are usually supplied with a 4 x AA battery box. You will need to swap this for a similar 6 x AA battery box or a 7.2V LiPo battery pack. Rechargeable batteries are a good idea when driving motors.

Chassis

Once the chassis is built, use some of the bolts suppled to fix the Raspberry Pi on the chassis and then attach the RRB3 onto the GPIO connector. Make sure its the right way arround, and that all the pins meet up with the socket.

The leads from the motors will thread up through the chassis and each pair of leads should go to one of the two screw terminals labelled L and R for (left and right). If you put the leads in the wrong way around, the direction of the motor will be opposite to that expected, so just swap them over if this happens.

Next, make sure that your Raspberry Pi's USB power lead is unplugged. From now on we are going to power it from batteries.

If the RRB3 is powered only from your Raspberry Pi, then the motor and OC outputs will not work, but the rangefinder, LEDs and I2C interface will work. To use the Motors and OC outputs, you must connect an external power source to the RRB3.

It is a good idea to leave the wheels off the robot chassis for now so that it does not unexpectedly drive itself off your table. One or both of the motors may spin as the Raspberry Pi starts up.

Wire the battery pack into the third pair of screw terminals. +V towards the outside of the board. The Raspberry Pi's power light should light up and it will start to boot.

Having your Pi set up for WiFi will allow you to connect to it wirelessly over SSH. So, you may want to plug in a USB WiFi dongle.

API Reference

General

The library implements a class called RRB3. This is only available for Python 2 and any Python programs that you write that use the libaray must be run as a super user.

To import the library and create an instance of the class, put this at the top of your Python program.

from rrb3 import *
rr = RRB3(9, 6)

The first parameter '9' is ther battery voltage (6 x 1.5V AA batteries). The second parameter ('6') is the motor voltage (6V for most low cost robot chassis motors). It is important to set these values correctly, as the library will manage the voltage supplied to the motors, to prevent them burning out or running too fast.

The rest is pretty straightforward, there are just a load of useful methods on the class that you can use.

LEDs

There are two LEDs built-in to the RaspiRobotBoard, called LED1 and LED2. Both of these can be turned on and off using the following methods:

To turn LED1 on just do:

rr.set_led1(1)

To turn it off again do:

rr.set_led1(0)

To control LED2 just do the same thing but using set_led2.

Switch Inputs

The sw1_closed() and sw2_closed() functions return true if the contacts for that switch are closed. By default, the switches are open. You can test out closing the switch by shorting the two contacts with a screwdriver.

The following test program will show you the state of each of the switch contacts.

from rrb3 import *

rr = RRB3()

while True:
    print("SW1=" + str(rr.sw1_closed()) + " SW2=" + str(rr.sw2_closed()))
    raw_input("check again")

Open Collector Outputs

The RRB3 has two high-power open collector outputs. These can each source up to 2A and so are suitable for driving loads at the battery voltage, such as high power LEDS, IR senders, alarm bells, relays etc.

To turn the Open Collector OC1 output on just do:

rr.set_oc1(1)

To turn it off again do:

rr.set_oc1(0)

To control OC2, substitute set_oc2 in place of set_oc1 in the examples above

Motor (High Level Interface)

There are two levels of command for controlling the motors. There is a high level interface that assumes that the motors are connected to wheels on a rover. These commands are forward, reverse, left, right and stop.

rr.forward()

... will start both motors running in the same direction to move the robot rover forwards. They will continue in this direction until another command is issued.

If you want to move forward for a certain amount of time, you can specify a number of seconds as an optional first argument. If you supply a second parameter between 0 and 1 this will control the speed of the motor. This is set to 0.5 as a defaut. If you want the motors to run indefinately, but also want to control the speed, then use 0 as the first patrameter.

Some examples:

rr.forward()       # forward half speed indefinately
rr.forward(5)      # forward for 5 seconds at half speed
rr.forward(5, 1)   # forward for 5 seconds at full speed

The commands left, right and reverse all work in the same way.

The stop command stops all the motors.

Stepper Motor Interface

There RRB3 can be used to drive a single bipolar stepper motor with one coil connected to the L motor driver and the other to the R terminals.

Two commands are available to make the motor step in one direction or the other:

rr.step_forward(5, 200)  # step in one direction for 200 steps with a 5ms delay between each phase change
rr.set_reverse(5, 200)   # other direction

Motor (Low Level Interface)

The low level interface is intended for control of the motors directly. It allows you to control the speed of each motor and its direction independently.

The method for this (set_motors) takes four arguments: the left speed, left motor direction, right spped and direction.

So to set both motors going forward at full speed, you would just use the following:

rr.set_motors(1, 0, 1, 0)

.. and half speed would be:

rr.set_motors(0.5, 0, 0.5, 0)

to send the motors both at half speed in opposite directions is:

rr.set_motors(0.5, 1, 0.5, 0)

Range Finder

If you fit the RRB3 with an SR-04 ultrasonic rangefinder, then you can use the following call to measure the distance to the enarest obstacle in cm.

rr.get_distance()

Hardware

You can find the schematic design file in the "hardware" section of this repo.

Absolute Maximum Ratings

Input Voltage: 6-12V (9 recommended when driving motors) Motor Current total average: 1.2A Motor Current total peak: 3.2A (built-in thermal shutdown) OC1 and OC2 output ccurrents: 2A at battery voltage (unprotected) Max current supplied to Pi (excluding motor current): 1.5A

Using I2C Displays

The I2C socket is pin compatible with these Adafruit displays:

To use these you will need to download Adafruit's Python library for the Pi from here.

Make sure that you plug the display in the right way around. The socket pins are labelled on the RRB3, make sure they match up with the labels on the display. You can use male to female jumper wires if you wish to put the display further away or its too big.

Example Projects

Have a look in the "examples" folder of this library for some examples using the RRB3.

Pin Usage

    RIGHT_PWM_PIN = 14
    RIGHT_1_PIN = 10
    RIGHT_2_PIN = 25
    LEFT_PWM_PIN = 24
    LEFT_1_PIN = 17
    LEFT_2_PIN = 4
    SW1_PIN = 11
    SW2_PIN = 9
    LED1_PIN = 8
    LED2_PIN = 7
    OC1_PIN = 22
    OC2_PIN = 27
    OC2_PIN_R1 = 21
    OC2_PIN_R2 = 27
    TRIGGER_PIN = 18
    ECHO_PIN = 23

FAQ

Q. My right motor doesn't work, but the left works fine and if I swap over the motors, the right motor still doesn't work. What's going on?

A. The RRB3 is designed to be compatible with older Raspberry Pi models that only had a 26 pin GPIO header. To have access to all the features of the RRB3 board, nearly every GPIO pin is used including some pins that can be used by other GPIO interfaces. In particular, the right motor channel uses GPIO pins 14, 10 and 25. GPIO14 doubles as the Raspberry Pi Serial interface's TX pin and GPIO10 doubles as the MOSI pin for the GPIO interface. If you are having trouble with the right motor channel, then make sure that both of these interfaces are turned off. On newer versions of Raspbian, you can do this using the Raspberry Pi Configuration tool that you will find on the main Raspberry menu under Preferences.

Settings

If you have an older version of Raspbian or are running 'headless', you can do the same thing using the raspi-config tool. Run the tool using the command:

    $ sudo raspi-config

Select the Advanced option and then turn off Serial and SPI.

raspirobotboard3's People

Contributors

simonmonk 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  avatar  avatar

Watchers

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

raspirobotboard3's Issues

R motor-output not working

Hi!

Great library! super easy to use!

I have a problem, my motor output R is not sending any voltage.

I'm using Raspbian Lite (2016-09-23), a RPI3 and the RRBv3f.

I installed from source, leds work, my two motors work (tested both on L output) but when sending rr.forward() only L has voltage, R does not.

Is there a problem with my board?

Thanks!

PID tunning not workin

I try to change PID value but no effect after changing Kp(High/Low) value between
Please share some basic tutorial for tuning

Warnings on installation

When running setup.py I receive a couple warnings.

/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
  warnings.warn(msg)
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)

on

Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux

I found the stackoverflow post https://stackoverflow.com/questions/8295644/pypi-userwarning-unknown-distribution-option-install-requires from which I gather that for these setup options to work there are additional prerequisites for the installation that need to be installed?

I don't think these are breaking issues but would be nice to not have warnings on install.

Pi 3

Hi,

I was wondering if the RasPi Robot Board v3 will work with Raspberry Pi 3?

Thanks

Raspirobotboard v3 GPIO pin use

I notice that the GPIO pins on the RaspberryPi that the Raspirobotboard v2 uses are nicely listed its README file as:

LEFT_GO_PIN = 17
LEFT_DIR_PIN = 4
RIGHT_GO_PIN = 10
RIGHT_DIR_PIN = 25
SW1_PIN = 11
SW2_PIN = 9
LED1_PIN = 7
LED2_PIN = 8
OC1_PIN = 22
OC2_PIN = 27
OC2_PIN_R1 = 21 (rev 1) or 27 rev 2
TRIGGER_PIN = 18
ECHO_PIN = 23

However, I do not see a pin listing for the Raspirobotboard v3 in its README. Are they the same? If not, where can I find them?

Raspirobotboard3 running motors

Hi,

I'm running one of your Raspirobotboards on a PI2 B+ and am having problems with it outputing enough volts to drive my motor. I have a 9V battery attached and when I use rr = RRB3(9, 3) the maximum voltage I can get seems to be about 1.5V. The motors I'm using are the standard yellow 3V ones the same as in the photo in your README.

As far as I can tell I have followed your instructions, but do you have any suggestions?

Thanks

Getting a linear actuator to stop.

First of all, thanks for the neat little board. I chose it as the best way to control a linear actuator using a Raspberry Pi 3. I managed to control the forward and reverse motion of the actuator, however I have failed to bring it to a stop in the middle of a forward/reverse motion.
i.e. rr.stop() has not worked for me.
The intended usage is to push high viscosity material through a nozzle and the ability to stop at a given time is of essence.
I would be grateful if you could shed any insight on a method to bring it to a stop during the middle of execution or at the command line as it is the only missing piece in my design.
So far all I've come up with is reversing at the command line.
Thanks.

I've created a few Arduino/C++ Examples for the board

Hi Simon, and others -
I don't know if anyone would be interested, but thought I would share anyway.
I've created a few Arduino and C++ examples, it is no where near complete, and it's really just a couple of examples of what can be done. I am using a project called RasPiArduino by Me-No-Dev - which adds the Raspberry PI to the Arduino IDE as a board core (https://github.com/me-no-dev/RasPiArduino). The couple of C++ examples I've done where done with WiringPi.
My Project can be found here: https://github.com/kd8bxp/RasPiRobot-Arduino
This is not a library, and it is still a work in progress. And I welcome feed back to help improve on it.
It works pretty good, the robot stutters a bit sometimes (I am having to bit-bang the pins for PWM, analogWrite isn't supported.)
I am planning on writing a few more C++ routines, "forward", "backward", "stop", "right", "left" ect, that can just be called from the CLI, but for now, this is it.

P.S. I am using a Raspberry PI Zero W, and RasPiRobot V3f board, with ultrasonic, and TT gear motors, with 3 18650 batteries (Which may be pushing it when they are fully charged, and I may drop to two 18650 batteries).

Can't SSH into PI

I am able to ssh into the pi from my laptop when the pi is being powered by its usual usb power lead.
But as soon as i unplug that and plug in the barrel jack from the battery pack (6xAA) into the raspirobotboard, the Pi powers up but even if i leave it on for 15min+ i still can't ssh into it. When i try to ping it i simply get 'destination host unreachable'.

Any idea what might be causing this?
I did run 'sudo iwconfig wlan0 power off' to turn off the power management on the wifi. But that didn't change anything.

When the pi is being powered by its usb i can turn the led's on and off and got the 'False' reply when testing the switch.

Software conflict

Hello,

I am using the Raspirobotboard3 to control a motor and it works great. However, I am also using another board (pi-plates relay board, stacked under the RRB3 on the RPi), and it works fine until I initialize the Raspirobotboard3 (in python, rr = RRB3(12,12), at which point my piplate board will no longer respond.

The piplate also uses GPIO port 25. I have tried running rr.cleanup (and GPIO.cleanup()) after I am done with the Raspirobotboard3 motor commands I need, but it does not work. Is there another way to completely reset/disable the Raspirobotboard3 after use?

Stepper Motor vs Optical Index Device

Wonder if the motors in the kit are stepper motors or require some sort of optical senor device to count steps.

Saw a video on YouTube explaining stepper motors contain many coils that alternate magnetic polarity to create motion. https://www.youtube.com/watch?v=eyqwLiowZiU

There was also this one explaining Rotary encoder - sensor arrangement
https://www.youtube.com/watch?v=dPBKTZw_xi4&t=212s

Please can you provide an example or this method to use and what hardware to get?
Just interested on how this work and want to show my enthusiasm for these little kits.

forward only runs one wheel

The forward command only runs one wheel. Reverse runs both.

Anybody seen this behavior?

Running on revision f of the board.

Low 5 volt from Raspirobotboardv3-yellow Lightning bolt

New V3f board on. Raspi 3 B+ Rev 4. Measured 4.64 vdc on Pin 4 and 3.28 on pin 1 with Raspirobot board connected to 12.5 volt LiPo battery. Runs ok, but why is voltage low? This is the second Rpasirobot board with this issue. Looking at board schematic and power converter design data sheet seems the R2 value is incorrect according to its data sheet and should be a lower value. Powering the Raspberry Pi without the. Raspirobotboard the 5/3 v supplies are 5.0 and 3.28 v.

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.