Created
October 22, 2011 06:21
-
-
Save edunham/1305708 to your computer and use it in GitHub Desktop.
Remote-Control Robot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************************* | |
* | |
* OrkMain.c | |
* ORKWare Wired RC Control Code | |
* Library for use with 2011 OSURC Robotics Kit (ORK). | |
* | |
* Copyright (C) 2011 OSURC. Released under the GNU LGPL3. | |
* http://oregonstate.edu/groups/osurc/ | |
* | |
* Written by Emily Dunham <[email protected]> | |
* Created 10/21/2011 | |
*************************************************************************/ | |
//#define L298 1 //Uncomment this definition to use the L298 (Upgrade Motor Driver) motor driver code | |
#include "OrkLib/OrkCore.h" | |
//Correlate button inputs with pins to which their buttons are attached | |
#define UP 6 | |
#define DOWN 7 | |
#define LEFT 4 | |
#define RIGHT 5 | |
//Option of fancy turning speeds, disable it by setting both to 127 | |
#define FAST 127 | |
#define SLOW 100 | |
int main(void) | |
{ | |
initializeCore(); | |
PORTF=0b11110000;//Make it so we can read the buttons | |
//For storing results that we read from the buttons | |
unsigned char up; | |
unsigned char down; | |
unsigned char left; | |
unsigned char right; | |
while(1){ | |
//Wait a little so the motor duty cycle doesn't get all confused | |
_delay_ms(50); | |
//Get correct button vals for this time through the loop | |
up=0;down=0;left=0;right=0; | |
if((~PINF)&(1<<UP)){up=1;} | |
if((~PINF)&(1<<DOWN)){down=1;} | |
if((~PINF)&(1<<LEFT)){left=1;} | |
if((~PINF)&(1<<RIGHT)){right=1;} | |
//Now drive based on button vals | |
//First, disregard contradictory inputs | |
if(left&&right){ | |
left=0; | |
right=0; | |
} | |
if(up&&down){ | |
up=0; | |
down=0; | |
} | |
//Then, drive as instructed | |
if(left&&up){ | |
setMotor(LeftMotor,SLOW); | |
setMotor(RightMotor,FAST); | |
} | |
else if(right&&up){ | |
setMotor(LeftMotor,FAST); | |
setMotor(RightMotor,SLOW); | |
} | |
else if(left&&down){ | |
setMotor(LeftMotor,-SLOW); | |
setMotor(RightMotor,-FAST); | |
} | |
else if(right&&down){ | |
setMotor(LeftMotor,-FAST); | |
setMotor(RightMotor,-SLOW); | |
} | |
else if(left){ | |
setMotor(LeftMotor,-SLOW); | |
setMotor(RightMotor,SLOW); | |
} | |
else if(right){ | |
setMotor(LeftMotor,SLOW); | |
setMotor(RightMotor,-SLOW); | |
} | |
else if(up){ | |
setMotor(LeftMotor,FAST); | |
setMotor(RightMotor,FAST); | |
} | |
else if(down){ | |
setMotor(LeftMotor,-SLOW); | |
setMotor(RightMotor,-SLOW); | |
} | |
else{ | |
setMotor(LeftMotor,0); | |
setMotor(RightMotor,0); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment