Go to Post Namaste. Maybe we all one day will spend our energy trying to raise our own level to match that of the competition rather than trying to tear others down. - Rich Kressly [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-02-2011, 19:32
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Registered User
FRC #3007 (ROBOTITANS)
Team Role: Alumni
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Minnesota
Posts: 20
Mandelbrot is an unknown quantity at this point
Will this autonomous code work?

Our build team has been working on the robot for quite a while and we haven't had time to check to see if our code will work. I don't think it's likely that we will have time soon, so I wanted to see if any of you on Chief Delphi would be able to spot any problems with it right off the bat.

This code is supposed to make the robot drive 100 inches and then stop, slowing down after every sixth of the target distance it has traveled.

Code:
void OperatorControl(void)
	{
		float 	X, Y, T, angle;
		float	armPosition;
		int 	sensors;                        
		double motorX = 0, motorY = 0;
		double targetDistance = 100;            //The total distance that the robot will drive
		double drivePeriod = 0.05;              //Time between motor update
		double printPeriod = 0.25;				//How long in between prints
		double driveExpiration, printExpiration; 
		double powerProfile[] = {0.3, 0.25, 0.2, 0.15, 0.1, 0.09}; //To reduce the robot speed gradually
		double distanceTraveled = 0;
		int speed = 0;                          //The element of the powerProfile matrix
		double currentSpeed = 0;                //The current speed the robot is traveling at
		int goneSixth = 1;                      //How many sixths of the total distance traveled
		double distancePerPulse = .075398223686;  //How many inches the robot travels after one pulse is sensed    
		int pulsePerRevolution = 250;           //The pulses on one revolution of the wheel
		int secPerMin = 60;
//		dashboard.init();
//		dashboard.log("Initializing...", "System State")
		printf("Initializing...\n");
		myRobot.SetSafetyEnabled(true);
		
		gyro.Reset();	// remove this for actual matches where gyro is reset before autonomous
		
		timer.Reset();
		timer.Start();
		
		driveExpiration = drivePeriod;
		printExpiration = printPeriod;
		motorX = 0;
		motorY = -0.1;
		
		while (IsOperatorControl())
		{
Code:
else if (stick1.GetRawButton(6) == true)
			{
				timer.Reset();
				timer.Start();
				distanceTraveled = 0;
				
				while (stick1.GetRawButton(6) == true && distanceTraveled <= targetDistance && timer.Get() < 4.0 )
				{
					if (timer.Get() > driveExpiration)
					{
						driveExpiration += drivePeriod;					//Adds drivePeriod to the driveExpiration
						
						//Calculates the current speed
						currentSpeed = ((motorFrontLeft.GetSpeed() + motorFrontRight.GetSpeed() + 
								motorRearLeft.GetSpeed() + motorRearRight.GetSpeed())/4);

						//Calculates the distance traveled
						distanceTraveled += distancePerPulse * (pulsePerRevolution/secPerMin) * currentSpeed * drivePeriod;					
						
						//Decreases the speed after every sixth of the target distance the robot has driven.
						if(distanceTraveled > (targetDistance * (goneSixth/7)))
						{
							speed++;
							goneSixth++;
						}
						myRobot.MecanumDrive_Cartesian(0, -powerProfile[speed], 0, angle);
						
						//printf("Period: %e Distance Traveled: %e   Current Speed:  %e\n" , drivePeriod, distanceTraveled, currentSpeed);
					}
					//Wait(waitPeriod);
					
				}
				myRobot.MecanumDrive_Cartesian(0, 0, 0, angle);             //Stops the robot
				//printf("Finished\n");                           	//Displays when the while loop ends
				while( stick1.GetRawButton(6) == true)
				{
					
				}
			}
Thanks in advance!
__________________
Humans are like slinkies. Practically useless, but still fun to push down stairs.
Reply With Quote
  #2   Spotlight this post!  
Unread 30-03-2011, 23:59
Dacilndak's Avatar
Dacilndak Dacilndak is offline
Matt'); DROP TABLE Users; --
AKA: Matthew Haney
FRC #3729 (Red Knights)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Denver, Colorado
Posts: 12
Dacilndak is an unknown quantity at this point
Re: Will this autonomous code work?

Well, first and foremost, all of this needs to be in void Autonomous(void), not void OperatorControl(void). If you upload this code and enable Autonomous, nothing will happen; the code above would run if you enabled Teleoperated and held down button #6 on your joystick.

Other than that, your logic seems sound.
__________________
Team 3729 - Raiders - Programming Team Co-Captain
2011 Colorado Regional Semifinalist
2011 Colorado Regional Rookie All-Star Award
2011 Colorado Regional Highest Rookie Seed Award
Reply With Quote
  #3   Spotlight this post!  
Unread 31-03-2011, 00:05
JLenhart's Avatar
JLenhart JLenhart is offline
Registered User
AKA: Jake
FRC #2614 (Mountaineer Area RoboticS (MARS))
Team Role: Mechanical
 
Join Date: Mar 2011
Rookie Year: 2009
Location: Morgantown, WV
Posts: 16
JLenhart has a spectacular aura aboutJLenhart has a spectacular aura about
Send a message via AIM to JLenhart Send a message via MSN to JLenhart
Re: Will this autonomous code work?

Keep in mind that the floor may be slightly elevated in some locations do to the general geography so it may take a little tweaking once you actually get there.

I know that we had to use two different autonomous modes for each side of the field in Palmetto because of this. One side was slightly more elevated than the other.
Reply With Quote
Reply


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


All times are GMT -5. The time now is 02:36.

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