Programming a Robot Using C++ Philipp Schrader & Tom Brown October 27, 2012



Similar documents
C/C++ Programming Guide for the FIRST Robotics Competition

FRC WPI Robotics Library Overview

EasyC. Programming Tips

CONTENTS. What is ROBOTC? Section I: The Basics

FTC Android Based Control System

Programming the VEX Robot

Best Robotics Sample Program Quick Start

LabVIEWTM. Robotics Programming Guide for the FIRST Robotics Competition. LabVIEW Robotics Programming Guide for FRC. January D-01

New Technology Introduction: Android Studio with PushBot

TETRIX Add-On Extensions. Encoder Programming Guide (ROBOTC )

How To Use First Robot With Labview

As it relates to Android Studio. By Phil Malone:

Creating a Project with PSoC Designer

After: bmotorreflected[port2]= 1; //Flip port2 s direction

J a v a Quiz (Unit 3, Test 0 Practice)

Programming LEGO NXT Robots using NXC

Unit 1: INTRODUCTION TO ADVANCED ROBOTIC DESIGN & ENGINEERING

Next Gen Platform: Team & Mentor Guide

ROBOTICS AND AUTONOMOUS SYSTEMS

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

KS3 Computing Group 1 Programme of Study hours per week

ANDROID BASED FARM AUTOMATION USING GR-SAKURA

ROBOTC Software Inspection Guide with Additional Help Documentation

Sources: On the Web: Slides will be available on:

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15

Sensors Collecting Manufacturing Process Data

Keil C51 Cross Compiler

File: C:\Program Files\Robotics Academy\RobotC\sample programs\rcx\arushi\robot_

Appium mobile test automation

E-Blocks Easy Internet Bundle

An Incomplete C++ Primer. University of Wyoming MA 5310

Title: Appium Automation for Mac OS X. Created By: Prithivirajan M. Abstract. Introduction

Arduino Lesson 1. Blink

Dr Robot C# Advance Sputnik Demo Program

Installing Java (Windows) and Writing your First Program

North Texas FLL Coaches' Clinics. Beginning Programming October Patrick R. Michaud republicofpi.org

Additional Guides. TETRIX Getting Started Guide NXT Brick Guide

Programmable Logic Controllers Definition. Programmable Logic Controllers History

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Advanced Programming with LEGO NXT MindStorms

New Technology Introduction: MIT App Inventor

Cloud computing is a marketing term that means different things to different people. In this presentation, we look at the pros and cons of using

Moving from CS 61A Scheme to CS 61B Java

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 OUTCOME 3 PART 1

Application Note: AN00141 xcore-xa - Application Development

Arduino Internet Connectivity: Maintenance Manual Julian Ryan Draft No. 7 April 24, 2015

Click to begin. Employees

Configuration Software User Instruction

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Modern Robotics, Inc Core Device Discovery Utility. Modern Robotics Inc, 2015

Background: Experimental Manufacturing Cell

Speed Based on Volume Values & Assignment (Part 1)

How to design and implement firmware for embedded systems

Unit 24: Applications of Pneumatics and Hydraulics

2/26/2008. Sensors For Robotics. What is sensing? Why do robots need sensors? What is the angle of my arm? internal information

Line Tracking Basic Lesson

ROBOTC Programming Competition Templates

How To Play Botball

Arduino Lesson 5. The Serial Monitor

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

Arduino Lesson 13. DC Motors. Created by Simon Monk

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

Kinect Interface to Play Computer Games with Movement

Building Robots with NXT and LEJOS. Introduc<on. What is the NXT Robot Michael Wooldridge liv.ac.uk)

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Statements and Control Flow

P-660HW-Tx v3. Quick Start Guide g Wireless ADSL 2+ 4-port Gateway. Version /2008 Edition 1

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Part I. Multiple Choice Questions (2 points each):

Pulse width modulation

1 Download & Installation Usernames and... Passwords

EE 472 Lab 2 (Group) Scheduling, Digital I/O, Analog Input, and Pulse Generation University of Washington - Department of Electrical Engineering

Project Development & Software Design

TRILOGI 5.3 PLC Ladder Diagram Programmer and Simulator. A tutorial prepared for IE 575 by Dr. T.C. Chang. Use On-Line Help

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Introduction to Java

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

P-660HW-Tx v g Wireless ADSL2+ 4-port Gateway DEFAULT LOGIN DETAILS. Firmware v3.70 Edition 1, 2/2009

How To Understand The Dependency Inversion Principle (Dip)

Business Process Management IBM Business Process Manager V7.5

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Designing VM2 Application Boards

Sample CSE8A midterm Multiple Choice (circle one)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Help. F-Secure Online Backup

Test Creation in QuickTest Professional

Example of Standard API

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

Assignment # 2: Design Patterns and GUIs

Arduino Lesson 14. Servo Motors

COSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan

Mitos P-Pump. product datasheet

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Programming Languages CIS 443

The C Programming Language course syllabus associate level

Designing a Home Alarm using the UML. And implementing it using C++ and VxWorks

Transcription:

Programming a Robot Using C++ Philipp Schrader & Tom Brown October 27, 2012

The robot has mechanical systems and electrical hardware, but needs a program to tell it what to do The program collects inputs from the drivers and sensors, and uses them to decide what motor output should be Different programming languages LabVIEW, C++, Java

Invented in the 1980 s Built as an extension on top of C Object-oriented programming language

Powerful and fast language; used widely in industry Steep learning curve, but after that development is fast Programming tools are less complicated, smaller, faster than LabVIEW

Writing instructions for machines to perform a set of desired tasks It's about controlling how inputs to a system affect the outputs of the system.

Centralizing where your source code is stored. Acts as a backup storage, history browser, and versioning for the code. Easily shows differences between two versions of the code. This includes the "current working version" with any modifications.

Wind River The Windows program used to compile code into programs for the robot. Primarily serves as a development environment for writing and debugging code.

Already-written code provided by FIRST to make robot programming easier Consists of classes that represent all common robot hardware Example: Compressor, DigitalInput, Victor, DriverStation, Solenoid, Gyro

SimpleRobot is a starting template to help teams quickly get a robot running. There are other templates such as IterativeRobot, but we will focus on SimpleRobot.

Cont'd #include ".h" class RobotDemo : public SimpleRobot { public: RobotDemo(void) { void (void) { void OperatorControl(void) { ; START_ROBOT_CLASS(RobotDemo);

Cont'd RobotDemo() is the constructor. This is where you initialize all members of the class. () is the function that gets called during the autonomous or hybrid period of a match. OperatorControl() is the function that gets called during teleop. Function gets called once and needs a loop to continue operator control.

// Declare drive components Joystick *stick; Victor *leftdrive; Victor *rightdrive; // Initialize components with port numbers RobotDemo(void) { stick = new Joystick(1); leftdrive = new Victor(1); rightdrive = new Victor(2);

Cont'd void OperatorControl(void) { while (IsOperatorControl()) { float lefty = stick->getrawaxis(2); float righty = stick->getrawaxis(4); // Tank drive leftdrive->setspeed(-lefty); rightdrive->setspeed(righty); Wait(0.005);

help the operators with controlling the robot. They are crucial in autonomous, but also very valuable for teleop. For example, appropriate sensors can be used to precisely position an arm on the robot.

Cont'd AnalogChannel *plowpot; RobotDemo(void) { plowpot = new AnalogChannel(2); void OperatorControl(void) { while (IsOperatorControl()) { printf("%d", plowpot->getvalue()); Wait(0.005);

Cont'd In our example, we are getting a feeling for how the potentiometer behaves. Some sensors have their own classes in. Use them whenever possible. Base Classes: AnalogChannel, DigitalInput : Encoder, Gyro, UltraSonic

We can use sensors to perform more sophisticated maneuvers than a human alone could do. For example, we can move an arm into the best scoring position consistently on the push of a button.

Cont'd Relay *leftplow; Relay *rightplow; RobotDemo(void) { leftplow = new Relay(1); rightplow = new Relay(2); void SetPlow(Relay::Value direction) { leftplow->set(direction); rightplow->set(direction);

Cont'd void OperatorControl(void) { while (IsOperatorControl()) { if (stick->getrawbutton(2)) { SetPlow(Relay::kForward); else if (stick->getrawbutton(3)) { SetPlow(Relay::kReverse); else { SetPlow(Relay::kOff);

Cont'd The previous slide shows a simple plow control without sensors. Button 2 lowers the plow. Button 3 raises the plow. If we add sensor feedback to the code, we can prevent the plow from going past mechanical limits. The next slide will incorporate feedback to the plow to prevent breaking itself.

Cont'd // Prevents the plow from going too far if (stick->getrawbutton(2) && (plowpot->getvalue() > 60)) { SetPlow(Relay::kForward); else if (stick->getrawbutton(3) && (plowpot->getvalue() < 250)) { SetPlow(Relay::kReverse); else { SetPlow(Relay::kOff);

According to the pneumatics setup and electrical rules by FIRST, pneumatics have special programming requirements. Solenoids and compressors have their own class in. Even if the compressor is not on the robot, it needs to be controlled by the robot itself.

Cont'd Solenoid *opengate; Solenoid *closegate; Compressor *compressor; RobotDemo(void) { opengate = new Solenoid(1); closegate = new Solenoid(2); compressor = new Compressor (9, 5);

Cont'd void OperatorControl(void) { opengate->set(false); closegate->set(true); while (IsOperatorControl()) { if (stick->getrawbutton(1)) { opengate->set(true); closegate->set(false); else if (stick->getrawbutton(4)) { opengate->set(false); closegate->set(true);...

Cont'd... // Only runs compressor until 120 psi if (!compressor->getpressureswitchvalue()) { compressor->start(); else { compressor->stop(); Wait(0.005);

The autonomous code works similarly to the teleop code. void (void) { while (Is()) { // Your code here...

Cont'd For this example we will make the robot lower and raise its plow until the end of the autonomous period. We will make use of a simple state machine that cycles between a state that raises the plow and a state that lowers the plow. We shall modify our SetPlow function as well. Switching between the states is done through the potentiometer.

Cont'd bool SetPlow(Relay::Value direction) { if ((direction == Relay::kForward && plowpot->getvalue() > 60) (direction == Relay::kReverse && plowpot->getvalue() < 260)) { leftplow->set(direction); rightplow->set(direction); return false; leftplow->set(relay::koff); rightplow->set(relay::koff); return true;

Cont'd void (void) { int state = 1; while (Is()) { switch (state) { case 1: if (SetPlow(Relay::kForward)) { state = 2; break;...

Cont'd... case 2: if (SetPlow(Relay::kReverse)) { case = 1; break;

Philipp Schrader Firmware Developer, Nuvation Research phil@spartonics.org Tom Brown Senior Software Developer, F.A. Servers tom.brown@spartonics.org