Thread: Copy Cat
View Single Post
  #13   Spotlight this post!  
Unread 12-03-2005, 13:13
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
Re: Copy Cat

Quote:
Originally Posted by thinkpad
Hey,

Is it controlled using a joystick when its getting recorded?

while recording, it's controlled in the same way you control it while driving. The way you record is to call the function storemotors while you are actually driving the bot. you don't want to call it all the time, though, because every time you call it it messes up whatever you've already got recorded.
Quote:
Originally Posted by Meandmyself
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.
Quote:
Originally Posted by thinkpad
and How many motors does it record, meaning will it record the movements of the arm or only the mobility?

You can record as many motors as you want. You just have to watch out because the more motor values you want to record simultaneously, the less accurate your playback will be. There's a simple way to get around this. Let me illustrate:

Suppose I want to control the motion of an arm moving up and down, and suppose I am controlling said arm with a PWM, however the only values I ever send to this arm are 0,127, and 254. I can do this two ways:
1) every third loop I record the value I'm sending to the arm. This is interspersed with the recording of the left and right motors, so that the left motor is stored every third loop and the right motor is stored every third loop.
Code:
void storemotors(void)
{
	static char lr = 0;

	switch (lr)						//alternate writing lmotor & rmotor
	case 0:
             {
		writeEE(address, lmotor);		//writes the motor value to EEPROM
		lr=1; break;
	}
             case 1:
	{
		writeEE(address, rmotor);
		lr=2; break;
	}
             case 2:
             {
                         writeEE(address, armmotor);           //writes arm motor value to EEPROM
                         lr = 0; break;
             }
	address++;					//increments address

}//end storemotors
and you do the same sort of thing in Readmotors to get the values out.

2)since the PWM value 255 is never sent to the motors, you can use 255 as a marker to tell the autonomous mode, "Hey! Arm going up now!" you would also need another unused pwm value to tell the autonomous that the arm is going down. When my team wrote our drive code, we had a little "dead zone" in the middle of the joystick's range, so that if the joystick was in between 117 and 137 the motor was set to 127. this gave us a whole bunch of unused pwm values.
Code:
void storemotors(void)
{
	static char lr = 0;
	static char armupordown = 0;
            

	if(armmotor== 254 && armupordown != 1)  //if the arm is going up and the arm wasn't going up last loop
	{
		writeEE(address, unused pwm value 1);  //stores motor going up marker
		armupordown = 1; //the arm just started going up
	}else if(armmotor == 127 && armupordown != 0) //if the arm has stopped moving and has just this loop stopped moving
	{
		writeEE(address, unused pwm value 2);  //motor stopped marker
		armupordown = 0;
	}else if (armmotor == 0 && armupordown != -1) //if arm just this loop started going down
	{
		writeEE(address, unused pwm value 3);  // motor going down marker
		armupordown= -1;
	}else 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
and then of course somthing similar in readmotors to recognize the markers.

Hope this helps. Ask as many questions as you like.
__________________
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