Go to Post you know you have overdosed to first when while you are reading all of these things, you can smile and say "oh yeah, i miss doing that" and then, you start to tear up and scream "I MISS FIRST!!!" - amanda547 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 27-01-2005, 21:35
Meandmyself's Avatar
Meandmyself Meandmyself is offline
Registered Magic Programming User
AKA: Gordon
#1123 (AIM robotics Crimson Lightning)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: springfield, VA
Posts: 26
Meandmyself will become famous soon enough
Copy Cat

I haven't seen any threads about copycat in a while, so I figure I'll share what I know. My team used a simplified version of copycat for the past two years as a backup to the code we couldn't get working. It's quite simple.
The idea is that you push a button in user control mode, then it writes to EEPROM the values you send to your motors. In autonomous mode, you play back the recording and that's your autonomous mode.

put this in your user_routines.c()
Code:
void storemotors(void)
{
	static char lr = 0;

	if (lr==0)						//alternate writing lmotor & rmotor
	{
		writeEE(address, lmotor);		//writes the motor value to EEPROM
		lr=1;
	}else
	{
		writeEE(address, rmotor);
		lr=0;
	}//endif
	address++;					//increments address

}//end storemotors





char readEE(unsigned short address) {

// Load address into address register
EEADRH = ((address>>8)&0x03);   //Bits 2-7 are masked off since EEPROM is only 1KB
EEADR =(address&0xFF);

//Configuration as per manual
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.RD =1;


return EEDATA;
}

void writeEE(unsigned short address, char data)
{
EEADRH = ((address>>8)&0x03);
EEADR =(address&0xFF);
EEDATA = data;

//Configuration as per manual
EECON1bits.EEPGD =0;
EECON1bits.CFGS =0;
EECON1bits.WREN =1; 
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA; 
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
}
put this in your user_routines_fast()
Code:
void readmotors(void)
{
	static char lr = 0;

	if (lr == 0)
	{
		lmotor = readEE(address2);
		lr = 1;
	}else
	{
		rmotor = readEE(address2);
		lr=0;
	}//endif

	address2++;

}//end readmotors
address and address2 are unsigned shorts defined in user_routines.c and _fast.c respectively. lmotor is the pwm you used for your left motor and rmotor is the address you used for your right motor.
you can alias lmotor and rmotor like this:
Code:
#define lmotor pwm01
#define rmotor pwm02
that should save you some cutting and pasting.

you call storemotors() so long as a certain button, like p1_sw_top, is pushed. That way, as long as the button is pushed, you're recording the data you send to the motors. call storemotors() only once you're done processing data and are ready to send it to the pwms.
like this:
Code:
	if (writebutton && (address <= 1023)) {storemotors();}		
//stores data in EEPROM for recall in auto mode
you call readmotors() in user_autonomous_code(). It reads out data from the EEPROM directly into the motors.
like this:
Code:
if (address2 <= 1023) {readmotors();}		//reads data from EEPROM to motors
else {lmotor = rmotor = 127;}
that's it. simple. The only problem you might run into is that it takes a while to write to the EEPROM. If you try to write two bits of data right after the other, it won't write the second bit. This is why I only write one motor per cycle. It definitely took me a while to figure that one out.

This is a really simplified version. It can only record one autonomous mode. The 1023 bytes of space should definitely allow you fifteen seconds of recording time. If not, you can always call storemotors and readmotors every other loop. My goal here is to help you understand copycat, not to provide you with the most function.

this code has not been tested on the new compiler, so if there's a big problem please tell me.

Please post if you have questions! If you have better versions of copycat please share, and explain too!
__________________
They call me the Idea man.
Not because my ideas work,
But because I have ideas...


I'm not a programmer. I'm an electrical guy who can program. If only I understood C!

www.aim-robotics.org //team website
www.tjhsst.edu/~gburgett //cool stuff for school
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Battlebots I.Q.- A serious threat to FIRST or a half thought up cheep copy? Joe Matt General Forum 75 17-10-2005 20:43
TEACHERS, Get a free copy of Mac OS 10.2 MattK Chit-Chat 26 07-03-2005 18:01
Program to copy list of files from Windows explorer as text into an application? Elgin Clock IT / Communications 6 30-12-2004 21:23
Science jokes..... Adam Y. Chit-Chat 20 10-12-2004 11:55
'Aluminum Angle/box/tube'-- copy of posting in General archiver 2000 0 24-06-2002 00:11


All times are GMT -5. The time now is 22:01.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi