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



Similar documents
Speed Based on Volume Values & Assignment (Part 1)

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

Line Tracking Basic Lesson

CONTENTS. What is ROBOTC? Section I: The Basics

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

Programming LEGO NXT Robots using NXC

Introduction to programming moway

Lego Robot Tutorials Touch Sensors

How To Turn On A Robot On A Computer On A Black Box On A Pc Or Macbook

RobotC Tutorial Packet I

How To Program An Nxt Mindstorms On A Computer Or Tablet Computer

understanding sensors

ROBOTICS AND AUTONOMOUS SYSTEMS

ROBOTC Programming Competition Templates

C.I. La chaîne d information LES CAPTEURS. Page 1 sur 5

Advanced Programming with LEGO NXT MindStorms

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

Programming the VEX Robot

Help on the Embedded Software Block

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Reading and Writing PCD Files The PCD File Format The Grabber Interface Writing a Custom Grabber PCL :: I/O. Suat Gedikli, Nico Blodow

FTC Android Based Control System

Programming Lego Robots using NQC

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

ROBOTC Software Inspection Guide with Additional Help Documentation

Servo Motor API nxt_motor_get_count nxt_motor_set_count nxt_motor_set_speed

How to Build a Simple Pac-Man Game

How to design and implement firmware for embedded systems

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

Dr Robot C# Advance Sputnik Demo Program

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

U-HID Pac-LED64 PacDrive U-HID LEDs

Modeling a GPS Receiver Using SystemC

YOSEMITE REGIONAL OCCUPATIONAL PROGRAM COURSE OUTLINE. COURSE TITLE: Robotics Engineering I ROP S1 Robotics Engineering I ROP S2

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

Timer A (0 and 1) and PWM EE3376

Lecture 7: Programming for the Arduino

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

THE NEXT GENERATION TRADING PLATFORM

Robotics and Automation Blueprint

EV3 Programming. Overview for FLL Coaches. A very big high five to Tony Ayad

Integration, testing and debugging of C code together with UML-generated sources

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

Designing an efficient Programmable Logic Controller using Programmable System On Chip

Implementation of eye tracking functions in the Presentation interface for the EyeLink-II eye tracking system, Version 0.9-Beta

What makes a good coder and technology user at Mountfields Lodge School?

The Basics of Robot Mazes Teacher Notes

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall

A BRIEF INTRODUCTION TO COMPUTER PROGRAMMING Scratch, LEGO MINDSTORMS, and Visual Basic. July 24, 2015

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

Quick Start Guide to computer control and robotics using LEGO MINDSTORMS for Schools

Tutorial for Programming the LEGO MINDSTORMS NXT

EasyC. Programming Tips

Keil C51 Cross Compiler

Programmable Logic Controllers Definition. Programmable Logic Controllers History

C4DI Arduino tutorial 4 Things beginning with the letter i

Lecture 22: C Programming 4 Embedded Systems

CENTERLINE Motor Control Centers Bulletin 2100 Smoke Detector Unit

Getting Started Manual

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

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?

Comparing RTOS to Infinite Loop Designs

FAQs. XAP Frequently Asked Questions. Software/Configuration

11. FLOWCHART BASED DESIGN

Applies to: F1PG200ENau Belkin Analogue Telephone Adapter (ATA) Firmware release notes

MANUAL FOR BREAKOUT BOARD HG06

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

ALON MP3 Dictaphone. User's manual. 1. Introduction 2. Audio Player 3. Voice Dictaphone 4. Phone calls recorder 5. Customer support.

Unit 1: INTRODUCTION TO ADVANCED ROBOTIC DESIGN & ENGINEERING

EVENT CODE LISTING. Administrator printed a copy of the receipt for the last customer transaction

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Downloading a Sample Program over USB

1006 Administrator printed a copy of the receipt for the last customer transaction

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

CHAPTER 11: Flip Flops

Introduction to Programming (in C++) Multi-dimensional vectors. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

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

Whack-a-Witch. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

AMI MARINE (UK) LTD BRIDGE NAVIGATIONAL WATCH ALARM SYSTEM (BNWAS) Operation Manual KW810

Add Door Phones to Your Phone System

Heat Surge Model X5C Fire Place Insert Service Manual Applies to all units w/ circuit board

Introduction. - Please be sure to read and understand Precautions and Introductions in CX-Simulator Operation Manual and

Introduction to the BackgroundWorker Component in WPF

4.2.2 Error Message and Troubleshooting

The While Loop. Objectives. Textbook. WHILE Loops

WRG EVENT CODE LISTING

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

While Loop. 6. Iteration

Introduction WELCOME TO LEGO MINDSTORMS EDUCATION

Installation Guide (No Router)

32F072BDISCOVERY. Discovery kit for STM32F072xx microcontrollers. Features. Description

A-145 LFO. 1. Introduction. doepfer System A LFO A-145

Working with microcontroller-generated audio frequencies (adapted from the Machine Science tutorial)

Congratulations for making the decision to become one of the many proud KT-X robot owners.

Find Me Call Forwarding

Media Gateway Hardware

For the next three questions, consider the class declaration: Member function implementations put inline to save space.

Programming LEGO NXT Robots using NXC

Transcription:

///////////////////////////////////////////////////////////////////////// // // This is the Program to control the Robot Head // Program By: Arushi Raghuvanshi // Date: Oct 2006 // ///////////////////////////////////////////////////////////////////////// // Define the sensor constants to use later in the program for readability const tsensors touchsensor = (tsensors) S2; //touch Sensor const tsensors leftlightsensor = (tsensors) S3; //light sensor const tsensors rightlightsensor = (tsensors) S1; //light sensor // Define Global Variables for use in the program int M[4][4]; // This is the 4x4 matrix for the gate int istate[4]; // This is 4x1 matrix for the input state int ostate[4]; // This is 4x1 matrix for the output state bool a, b; bool P, Q; // a and b are two inputs, mapped to some combination of sen // P and Q are two outputs, mapped to some combination of mo void setmatrixm() // Initialize the matrix for the gate // The program behavior changes just by changing this matrix // This matrix here is a simple identity matrix // implying that inputs are directly connected to outputs M[0][0] = 1; M[0][1] = 0; M[0][2] = 0; M[0][3] = 0; M[1][0] = 0; M[1][1] = 1; M[1][2] = 0; M[1][3] = 0; M[2][0] = 0; M[2][1] = 0; M[2][2] = 1; M[2][3] = 0; M[3][0] = 0; M[3][1] = 0; M[3][2] = 0; M[3][3] = 1; void setinputstate() // Initialize the input matrix, by looking at the input variables a and b istate[0] =!a &!b; //00 istate[1] =!a & b; //01 istate[2] = a &!b; //10 istate[3] = a & b; //11 void multiplymatrix() // do the regular matrix multiplation of M with istate to get matrix ostate int i, j; for (i=0; i<4; i++) ostate[i] = 0; for (j=0; j<4; j++) ostate[i] = ostate[i] + (M[i][j] * istate[j]); Page 1 of 1

// if the value is negative, set it to positive, since sign is lost in // measurement of quantum gate output if (ostate[i] < 0) ostate[i] = ostate[i] * (-1); void interpretoutputstate() // interpret ostate matrix in terms of P and Q actions int total=0; int i=0; int onecounter=0; int x=0; // First reset P & Q P = false; Q = false; // first count how many ones total = ostate[0] + ostate[1] + ostate[2] + ostate[3]; // probablity of each '1's in the matrix is equally randomized // following routine returs a number from 0 to total-1 // so if the total # of ones are 2, then the following routine // returns either 0 or 1, with equal probability if (total > 1 ) x = random(total-1); x = 0; // Now out of the ostate entries that have a value of '1', we pick // an the entry based on the random value above for (i=0; i<4; i++) if (ostate[i]!= 0) if (x == onecounter) // set the action flags, use the value of i to calculate P and Q switch (i) case 0 : P = false; Q = false; break; case 1 : P = false; Q = true; break; case 2 : P = true; Q = false; break; case 3 : P = true; Q = true; break; // the above switch/case can also be replaced with following two state // P = (bool) i/2; // Q = (bool) i%2; break; // got a match, break out of for loop onecounter++; Page 2 of 2

// Following two routines are the only routines that are specific to // a particular robot design void executeaction() // P and Q are either true or false based on output matrix // This routine translates P and Q into motor actions // Port A is attached to base motor, rotates the head, can move at normal spee // Port B has two motors attached, moves both eyebrows - needs to move at low // Port C has 3 motors attached - moves 2 eyes and mouth - // This needs to move at low power, and also need to move back & fo // so has to know previous state if (P) // turn the head right, wait a while, and turn it back straight motor[motora] = 100; wait1msec(700); motor[motora] = -100; wait1msec(700); motor[motora] = 0; // do not rotate the head motor[motora] = 0; if (Q) // Move eyebrows back and forth motor[motorb] = 15; wait1msec(250); motor[motorb] = -15; wait1msec(100); motor[motorb] = 0; // Move eyes and mouth, and come back to normal position motor[motorc] = 30; wait1msec(500); motor[motorc] = -30; wait1msec(500); motor[motora] = 0; // do not change any facial expressions motor[motorb] = 0; motor[motorc] = 0; void checksensors() // This routine checks the value of sensors and sets the variables a and b // Check for a significant difference (10%) between left light sensor and righ // To test, shine a flashlight in front of left sensor if (SensorValue(leftLightSensor) > (SensorValue(rightLightSensor)+10)) Page 3 of 3

a = true; a = false; // Check if either of the touch sensors are pressed // Both touch sensors are attached to same port and are OR'ed if (SensorValue(touchSensor) == 1 ) b = true; b = false; ClearSensorValue(leftLightSensor); ClearSensorValue(rightLightSensor); ClearSensorValue(touchSensor); // This is the main program task main() // Initialize sensor types, connected to three ports SetSensorType(leftLightSensor, sensorreflection); SetSensorType(rightLightSensor, sensorreflection); SetSensorType(touchSensor, sensortouch); // Clear all sensors ClearSensorValue(leftLightSensor); ClearSensorValue(rightLightSensor); ClearSensorValue(touchSensor); // Initialize all motors to 0 - stopped motor[motora] = 0; motor[motorb] = 0; motor[motorc] = 0; // Set the matrix for the gate setmatrixm(); while (true) PlayTone(220, 10); //debugging tool - Plays a 220hz tone for 1 second wait1msec(1000); //wait 5 seconds before next cycle checksensors(); //Check Sensors and set input variables setinputstate(); //Create input matrix multiplymatrix(); //Compute output matrix interpretoutputstate(); //Determine what actions to do executeaction(); //Execute those actions PlayTone(990, 50); //debugging tool - Plays a 330hz tone for 1 second wait1msec(3000); //wait 5 seconds before next cycle Page 4 of 4