Está en la página 1de 14

Essay Collective work

Done by:

The purpose of our project is to write a program that will provide interaction, understanding of multiple robots that will be controlled by iphone. In order to

check whether the algorithm is right, we give to robots a certain task, and if they will do the job perfectly well it will be a measure of the success of the algorithm. The aim of our project is to allow multiple robots jointly pushed a single object. When main robot do something the signal goes to secondary robots and the do the same action. For a better understanding, let's draw a scheme:

Plan of our work: 1) Writing an app for Iphone, that allow to us to control car. 2) Set up bluetooth device to Main Cars arduino. 3) Set up the IR sender and receiver to the secondary robots.

For navigating with robots motion we used following logic. If (robots need to move forward) { we give the HIGH signal to the analog pins and the certain same value to the digital pins on the each wheel } else if (robots need to turn left or right) { we give the HIGH signal to the two of the analog pins and LOW signal to the others and the certain same value to the digital pins on the each wheel } else if (robots need to stop){ we give the zero signal to the digital and analog pins }

Writing an app for Iphone, that allow to us to control car. For writing an app for iphone we use objective-c language(this language used to write programs for iphone and ipad). Our programs design will consist of four buttons:Forward Back Left Right, so if we will push button Forward robot must go forward and so on. For every button we write the method, which send signal to robot. Here is example of code, that we wrote, creating the buttons:
// // // // // // // ViewController.h MyGame=) Created by Apple on 30.09.13. Copyright (c) 2013 Alibek. All rights reserved.

#import <UIKit/UIKit.h> @interface ViewController : UIViewController - (IBAction)Forward:(id)sender; - (IBAction)Back:(id)sender; - (IBAction)Right:(id)sender; - (IBAction)Back:(id)sender; @end // // // // // // // ViewController.m MyGame=) Created by Apple on 30.09.13. Copyright (c) 2013 Alibek. All rights reserved.

#import "ViewController.h" #import "ViewController2.h" #import "ViewController3.h" #import "ViewController4.h" #import "ViewController5.h" #import "ViewController6.h" #import "ViewController7.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {

[super viewDidLoad];

} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

- (IBAction)Forward:(id)sender { ViewController2 *second=[[ViewController2 alloc]initWithNibName:nil bundle:nil]; [self presentViewController:second animated:YES completion:NULL]; } - (IBAction)Back:(id)sender { ViewController3 *third=[[ViewController3 alloc]initWithNibName:nil bundle:nil]; [self presentViewController:third animated:YES completion:NULL]; } - (IBAction)Right:(id)sender { ViewController4 *fourth=[[ViewController4 alloc]initWithNibName:nil bundle:nil]; [self presentViewController:fourth animated:YES completion:NULL]; } - (IBAction)Left:(id)sender { ViewController5 *fifth=[[ViewController5 alloc]initWithNibName:nil bundle:nil]; [self presentViewController:fifth animated:YES completion:NULL]; } - (IBAction)start:(id)sender { NSString *string[3]; string[0] string[1] string[2] NSMutableArray *array=[NSMutableArray arrayWithObjects:string count:3]; _firstPlayer.text=[array objectAtIndex:rand()%3]; _secondPlayer.text=[array objectAtIndex:rand()%3]; [self comparison:_firstPlayer.text compareWith:_secondPlayer.text]; if((k==3 && l!=3) ) { UIAlertView* mes=[[UIAlertView alloc] initWithTitle message Player" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [mes show]; _firstWinner.text mystr1 k=0; l=0; } else if (k==3 && l!=3) { UIAlertView* mes=[[UIAlertView alloc] initWithTitle: message Player" delegate:self cancelButtonTitle:@"Ok"

otherButtonTitles: nil];

[mes show]; _firstWinner.text mystr1 k=0; l=0; } }

For connecting our program with arduino we use blutooth, so for our program we must add BLUTOOTH framework:

/* * @file CBCentral.h * @framework CoreBluetooth * * @discussion Representation of a remote central. * * @copyright 2012 Apple, Inc. All rights reserved. */ #import <CoreBluetooth/CBDefines.h> #import <Foundation/Foundation.h>

/*!

* @class CBCentral * * @discussion Represents a remote central. * */ NS_CLASS_AVAILABLE(NA, 6_0) CB_EXTERN_CLASS @interface CBCentral : NSObject <NSCopying> /*! * @property UUID * * @discussion The UUID of the central. This UUID can be used to retrieve the equivalent @link CBPeripheral @/link object via @link retrievePeripherals: @/link. * * @deprecated Use the {@link identifier} property instead. */ @property(readonly, nonatomic) CFUUIDRef UUID NS_DEPRECATED(NA, NA, 5_0, 7_0); /*! * @property identifier * * @discussion The unique identifier associated with the central. This identifier can be used to retrieve the equivalent @link CBPeripheral @/link object * via @link retrievePeripheralsWithIdentifiers: @/link. */ @property(readonly, nonatomic) NSUUID *identifier; /*! * @property maximumUpdateValueLength * * @discussion The maximum amount of data, in bytes, that can be received by the central in a single notification or indication. * @see updateValue:forCharacteristic:onSubscribedCentrals: */ @property(readonly, nonatomic) NSUInteger maximumUpdateValueLength; @end

Set up bluetooth device to Main Cars arduino. I wrote program with LEDs, its just analog of real program. If on main car LED is red, secondary car must go forward, if yellow car must go left and so on.

The main conclusions of modules HC-04/HC-06: UART_TX (pin 1), UART_RX (pin 2), UART_CTS (pin 3), UART_RTS (pin 4) - pins UART. 3,3 V (pin 12) - 3.3V. GND (pin 13) - total. PIO1 (pin 24) - an indicator of the operating mode. If a connection is not established - the LED flashes when set, stays on. For modules HC-03/HC-05 there are some differences. UART and power lines are the same, however: PIO8 (pin 31) - an indicator of the operating mode. PIO9 (pin 32) - the status of the connection if the connection is established, then the output will be high. PIO11 (pin 34) - enable input mode AT-commands (must submit a log. 1).

Step across the terminals on the module is only 1.5mm, so you have to take a soldering iron and solder the wires to the module. Only 5 wires to solder, but the LED is not necessarily connected, it indicates the status. Now solder the wires and connect the Bluetooth module as follows: output 3.3V Arduino - to 12 pin of the module conclusion Arduino GND - to 13 pin of the module conclusion Arduino TX - 2 to RX pin of the module conclusion Arduino RX - to 1 pin of the module TX The transfer of data from the Arduino via Bluetooth

Then write a simple sketch to send messages from Bluetooth module to the computer. int cnt = 0, / / counter void setup () { Serial.begin (9600) / / initialize port } void loop () { cnt + +; Serial.print ("Hello BB from Arduino! Counter:"); / / derive the inscription

Serial.println (cnt); / / show the counter and newline delay (1000); / / wait 1 second } Bidirectional communication via Bluetooth The next step is to write a simple little program bidirectional communication between the Arduino and the computer. In the chart I added the LED by connecting it to the 12 pin of Arduino, a current-limiting resistor . But you can use built-in LED ( usually 13 pin ) . char incomingByte; / / incoming data int LED = 12 ; / / LED is connected to the 12 pin of void setup () { Serial.begin ( 9600 ) / / initialize port pinMode (LED, OUTPUT); Serial.println ("Press 1 to LED ON or 0 to LED OFF ..."); } void loop () { if (Serial.available ()> 0) { / / if the data came incomingByte = Serial.read (); / / read the byte if (incomingByte == '0 ') { digitalWrite (LED, LOW); / / if 1, then turn off the LED Serial.println ("LED OFF. Press 1 to LED ON!"); / / And display a message back } if (incomingByte == '1 ') { digitalWrite (LED, HIGH); / / if 0, then turn on the LED Serial.println ("LED ON. Press 0 to LED OFF!"); }

} } The program works very simply . After the start-up or reset the device to the serial port of a message is displayed prompting you to press 1 or 0. Depending on the figures down LED will light up or go out . And also, from the Arduino will print the LED light , or off.

IR sender and reciever. Connecting transmitter like the following picture:

Then, connecting receiver like that:

Here is code for main car: /* include <IRremote.h> // IR remote control library const int numberOfKeys = 1; const int

firstKey = 4; // the first pin of the 5 sequential pins connected to buttons boolean buttonState[numberOfKeys]; boolean lastButtonState[numberOfKeys]; long irKeyCodes[numberOfKeys] = { 0x18E758A7, //0 key }; IRsend irsend; void setup() { for (int i = 0; i < numberOfKeys; i++){ buttonState[i]=true; lastB uttonState[i]=true; int physicalPin=i + firstKey; pinMode(physicalPin, INPUT); digitalWrite(physicalPin, HIGH); // turn on pullups } Serial.begin(9600); } void loop() { for (int keyNumber=0; keyNumber<numberOfKeys; keyNumber++) { int physicalPinToRead=keyNumber+4; buttonSta te[keyNumber] = digitalRead(physicalPinToRead); if (buttonState[keyNumber] != lastButtonState[keyNumber]) { if (buttonState[keyNumber] == LOW) { irsend.sendSo ny(irKeyCodes[keyNumber], 32); Serial.println("Sending"); } lastButtonState[keyNum ber] = buttonState[keyNumber]; } } }

Code for receiver: /*

IR_remote_detector sketch An IR remote receiver is connected to pin 2. The LED on pin 13 toggles each time a button on the remote is pressed. */ #include <IRremote.h> //adds the library code to the sketch const int irReceiverPin = 2; //pin the receiver is connected to const int ledPin = 13; IRrecv irrecv(irReceiverPin); //create an IRrecv object decode_results decodedSignal; //stores results from IR detector void setup() { pinMode(ledPin, OUTPUT); irrecv.enableIRIn(); } boolean lightState = false; unsigned long last = millis(); // Start the receiver object //keep track of whether the LED is on //remember when we last received an IR void loop() { if (irrecv.decode(&decodedSignal) == true) //this is true if a message has been received { if (millis() - last > 250) { //has it been 1/4 sec since last message lightState = !lightState; //toggle the LED digitalWrite(ledPin, lightState); } last = millis(); irrecv.resume(); // watch out for another message } } When you press the button, the LED on the other Arduino should switch on. When you press it again, the LED switch off.

También podría gustarte