RobotOpen_Lib_v1_1_x.pdf

(62 KB) Pobierz
RobotOpen Arduino Library Reference
Version 1.1.x Release
www.RobotOpen.biz
1
1.1
Introduction
Overview
The RobotOpen Arduino Library provides an easy to use abstraction layer to quickly begin programming
and controlling your robots with RobotOpen. The 1.1.x release is currently compatible with the
RobotOpen Control Shield for Arduino coupled with the boards listed below.
1.2
Supported Hardware
Ethernet Arduino
Arduino Uno + Ethernet Shield
Arduino Duemilanove + Ethernet Shield
Sparkfun Ethernet Pro
1.3
Recommended Hardware
Windows Based PC with Java 6+
Logitech Dual Action USB Game Pad
Ethernet Arduino + RobotOpen Control Shield
1.4
Installation
Before installing the RobotOpen library, rst verify that you are running the latest version of the
Arduino IDE. The latest version of the RobotOpen Arduino library can be found at www.robotopen.biz.
Download and extract the zip le. You should be left with a folder named "RobotOpen". You
can then place this folder into your Arduino installation directory. On Windows this will be
located under Arduino/libraries. On OS X you will need to right click the Arduino.app le and
select "Show Package Contents". Navigate to Contents/Resources/Java/libraries and place the
RobotOpen folder in this directory. If you are upgrading your version of the RobotOpen library
you can safely delete the "RobotOpen" directory before copying in the new version.
1
RobotOpen Arduino Library Reference
Version 1.1.x Release
www.RobotOpen.biz
1.5
Driver Station App
The Driver Station app is a simple Java application to allow control of your RobotOpen powered
robot. This can be obtained from www.robotopen.biz. Please view the getting started video
listed on the site to learn more.
1.6
Examples
Now that you have the RobotOpen library loaded up, simply open the Arduino IDE and select File
» Examples » RobotOpen » TankDrive. This is the simplest example bunded into the RobotOpen
library that shows how you should model your RobotOpen projects. For this example, all of the
code is provided to get a basic robot up and running in a Tank Drive con guration. By default, the
Logitech Dual Action USB Game Pad will work out of the box.
2
RobotOpen Arduino Library Reference
Version 1.1.x Release
www.RobotOpen.biz
2
RobotOpen Class
The RobotOpen class is the core of the RobotOpen library. It is important to note that the inner
workings of RobotOpen use what are called "bundles" to send and receive data between the
driver station and robot controller. Every bundle is identi ed by a bundle ID that is a single
character. Typically 0-9, a-z, or A-Z. When accessing the low level data in RobotOpen, you will
use these bundle IDs.
2.1
RobotOpen::begin()
Returns: void
This function initializes communications and con gures RobotOpen. This should only be called
once from the setup() function in the Arduino environment.
2.2
RobotOpen::pollDS()
Returns: void
This function processes any data that has been received from the driver station and updates all
joystick objects. It should be called at the beginning of every program loop.
2.3
RobotOpen::outgoingDS()
Returns: void
This function noti es RobotOpen that all of the robot code has nished executing and any data
waiting to be sent back to the driver station should happen now. This should be called at the end
of every program loop.
2.4
RobotOpen::setPWM(int pwmChannel, int value)
int pwmChannel:
The PWM output to set. See the Digital Sidecar IO Constants near the end of
this document for possible values. Example: SIDECAR_PWM7.
int value:
The PWM value to set. Use a joystick makePWM function here or manually pass a
value between 0-255.
Returns: void
This function sets a motor or PWM value on a speci c PWM output of the digital sidecar.
2.5
RobotOpen::setSolenoid(int solenoidChannel, boolean value)
int solenoidChannel:
The solenoid output to set. See the Constants section near the end of this
document for possible values. Example: SOLENOID_3.
boolean value:
Set the solenoid on or o . HIGH for ON, LOW for OFF.
Returns: void
This function sets a solenoid output to either ON or OFF. NOTE: You must be using the RobotOpen
Solenoid Shield.
3
RobotOpen Arduino Library Reference
Version 1.1.x Release
www.RobotOpen.biz
2.6
RobotOpen::enabled()
Returns: boolean
This will return to you a boolean of the current state of the robot. True corresponds to enabled.
False corresponds to disabled.
2.7
RobotOpen::publishAnalog(int pin, unsigned char bundleID)
int pin:
The analog pin on the RobotOpen Shield that you would like to send back to the DS. The
Analog Input Constants listed below can be passed in for this value.
unsigned char bundleID:
A unique single character that identi es this bundle. This should be
passed in single quotes. Typical values include 0-9, a-z, and A-Z.
Returns: void
This method measures the voltage of the speci ed analog pin and sends it back to the driver
station as a value between 0-1023. The bundleID is simply a method to identify the data "bundle"
on your driver station.
2.8
RobotOpen::publishDigital(int pin, unsigned char bundleID)
int pin:
The digital pin on the RobotOpen Shield that you would like to send back to the DS. The
Digital Sidecar IO Constants listed below can be passed in for this value.
unsigned char bundleID:
A unique single character that identi es this bundle. This should be
passed in single quotes. Typical values include 0-9, a-z, and A-Z.
Returns: void
This method measures a digital sidecar pin state (0vdc or 5vdc) and sends it back to the driver
station as either a 0 (0vdc signal) or 255 (5vdc signal). The bundleID is simply a method to
identify the data "bundle" on your driver station.
2.9
RobotOpen::publishByte(unsigned char value, unsigned char bundleID)
unsigned char value:
The single byte (8 bit) value that you would like to send back to the DS.
unsigned char bundleID:
A unique single character that identi es this bundle. This should be
passed in single quotes. Typical values include 0-9, a-z, and A-Z.
Returns: void
This method sends a single byte back to the driver station. The bundleID is simply a method
to identify the data "bundle" on your driver station.
4
RobotOpen Arduino Library Reference
Version 1.1.x Release
www.RobotOpen.biz
2.10
RobotOpen::publishInt(unsigned int value, unsigned char bundleID)
unsigned int value:
The int (16 bit) value that you would like to send back to the DS.
unsigned char bundleID:
A unique single character that identi es this bundle. This should be
passed in single quotes. Typical values include 0-9, a-z, and A-Z.
Returns: void
This method sends a single int back to the driver station. The bundleID is simply a method to
identify the data "bundle" on your driver station.
2.11 RobotOpen::publishLong(long value, unsigned char bundleID)
long value:
The long (32 bit) value that you would like to send back to the DS.
unsigned char bundleID:
A unique single character that identi es this bundle. This should be
passed in single quotes. Typical values include 0-9, a-z, and A-Z.
Returns: void
This method sends a single long back to the driver station. The bundleID is simply a method
to identify the data "bundle" on your driver station.
2.12
RobotOpen::getBundleSize(unsigned char bundleID)
Returns: int
All data from the driver station is sent in bundles. Normally you will only deal with joystick
values coming from your driver station. Each joystick should be in its own bundle. Joystick 1 is
typically in bundle ’0’ and Joystick 2 is typically in bundle ’1’. This function allows you to get the
size (number of bytes) of a particular bundle that you are receiving from the DS. If the bundle
cannot be found, -1 is returned.
2.13
RobotOpen::getComponent(unsigned char bundleID, int componentIndex)
Returns: int
All data from the driver station is sent in bundles. Normally you will only deal with joystick
values coming from your driver station. Each joystick should be in its own bundle. Joystick 1 is
typically in bundle ’0’ and Joystick 2 is typically in bundle ’1’. This function allows you to get the
value from a speci c joystick component or byte in your joystick bundle. componentIndex allows
you to specify a byte index between 0 ( rst component) and the number of components in the
bundle - 1. Valid values range between 0-255. An error will be returned as -1.
5
Zgłoś jeśli naruszono regulamin