Go to Post Every time i look at my watch and see 3:65 o'clock I always thing, darn i gotta get a new watch... - Kyle [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 02-02-2011, 21:03
Lawlhwut Lawlhwut is offline
Registered User
None #2853
 
Join Date: Jan 2011
Location: Hawaii
Posts: 17
Lawlhwut is an unknown quantity at this point
Autonomous Not Working

Code:
#include "WPILib.h"

class RobotDemo : public SimpleRobot
{
	// Declare Motors
	RobotDrive myRobot;
	Victor LeftDrive;
	Jaguar RightDrive;
	Jaguar Lift;
	Jaguar Claw;

	// Declare Joysticks
	Joystick LeftStick;
	Joystick RightStick;

	// Declare Sensors
	Encoder LeftEncoder, RightEncoder;
	Gyro gyro1;
	static const float Kp = 0.03;

public:
	
	
	
	
	
	RobotDemo(void):

		// Set Channels
		myRobot(1,2),
		LeftDrive(1),
		RightDrive(2),
		Lift(5),
		Claw(4),
		LeftStick(1),
		RightStick(2),
		LeftEncoder(3,4,true),
		RightEncoder(5, 6, true),
		gyro1(7)
		
		{
			// Set Motor Expiration
			LeftDrive.SetExpiration(0.005);
			RightDrive.SetExpiration(0.005);
			Lift.SetExpiration(0.005);
			Claw.SetExpiration(0.005);
			
			// Set Encoder Displacement Values
			LeftEncoder.SetDistancePerPulse(0.26333);
			RightEncoder.SetDistancePerPulse(0.26333);
		}
		
	void Autonomous(void)
	{
		//Delcare variables
		int AutoStep = 1;
		
		// Start sensors
		LeftEncoder.Start();
		RightEncoder.Start();
		gyro1.Reset();

		// Run while in autonomous mode
        while(IsAutonomous())
		{							
        	// Return sensor values for tracking		
        	float leftdistance = LeftEncoder.GetDistance();  
        	float rightdistance = RightEncoder.GetDistance();
        	float angle = gyro1.GetAngle();	
        	
        	// Update LCD with new data
        	DriverStationLCD *screen = DriverStationLCD::GetInstance();	
        	screen->PrintfLine(DriverStationLCD::kUser_Line1,"Left Motor",LeftDrive.Get());
        	screen->PrintfLine(DriverStationLCD::kUser_Line2,"Right Motor",RightDrive.Get());
        	screen->PrintfLine(DriverStationLCD::kUser_Line3,"Direction",gyro1.GetAngle());
        	screen->UpdateLCD();
        	
			switch(AutoStep)
			{
				case 1:
				{
					// Move forward to set position
					myRobot.Drive(1.0, -angle / Kp);	
					Wait(0.005);
	
					// Stop if distance is reached
					if(leftdistance >= 4953 || rightdistance >= 4953)
					{
						LeftDrive.Set(0);
						RightDrive.Set(0);
						AutoStep = 2;
					}
					break;
				}
				
				case 2:
				{
					// Drop tube
					Claw.Set(1.0);
					Wait(1.0);
					Claw.Set(0);

					AutoStep = 3;
					break;
				}
				
				case 3:
				{
					// Adjust for gameplay
					LeftDrive.Set(-0.5);
					RightDrive.Set(-0.5);
					Wait(1.0);
					while(gyro1.GetAngle() > -180 || gyro1.GetAngle() < 180)
					{
						LeftDrive.Set(-0.25);
						RightDrive.Set(0.25);
						Lift.Set(-1.0);
					}
					while(IsAutonomous())
					{
						Wait(0.1);
					}
					break;
				}
			}
		}
	}

	void OperatorControl(void)
	{
		// Reset motors for teleoperator
		LeftDrive.Set(0);	
		RightDrive.Set(0);
		Lift.Set(0);
		Claw.Set(0);
		gyro1.Reset();
		
		// Run while in operator control mode
		while(IsOperatorControl())
		{
			// Get Drive
			float lefty = (LeftStick.GetY());
			float righty = (RightStick.GetY());
			
			// Desensitize joysticks
			lefty = ((lefty/128)*(lefty/128));
			righty = ((righty/128)*(righty/128));
			
			// Set Drive
			LeftDrive.Set(lefty);
			RightDrive.Set(righty);
			
			// Claw Control
			if(RightStick.GetRawButton(2))
			{
					Claw.Set(1.0);
			}
			else
			{
				if(RightStick.GetRawButton(3))
				{
					Claw.Set(-1.0);
				}
				else
					Claw.Set(0.0);
			}
			
			// Lift Control
			if(LeftStick.GetRawButton(2))
			{
				Lift.Set(1.0);
			}
			else
			{
				if(LeftStick.GetRawButton(3))
				{
					Lift.Set(-1.0);
				}
				else
					Lift.Set(0.0);
			}
			
			// Update LCD with new data
			DriverStationLCD *screen = DriverStationLCD::GetInstance();	
			screen->PrintfLine(DriverStationLCD::kUser_Line1,"Left Motor:",LeftDrive.Get());
			screen->PrintfLine(DriverStationLCD::kUser_Line2,"Right Motor:",RightDrive.Get());
			screen->UpdateLCD();
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Builds flawlessly, but when we try to run it on our prototype robot, the communication is lost and the robot acts funky.

Solutions?
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2011, 21:54
Lawlhwut Lawlhwut is offline
Registered User
None #2853
 
Join Date: Jan 2011
Location: Hawaii
Posts: 17
Lawlhwut is an unknown quantity at this point
Re: Autonomous Not Working

Addition:

Nothing is wrong with the robot. We tested other programs and it worked perfectly fine.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2011, 20:34
PatrickS's Avatar
PatrickS PatrickS is offline
I get my code from /dev/null
FRC #1742 (Shockwave)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Oklahoma City
Posts: 21
PatrickS is an unknown quantity at this point
Re: Autonomous Not Working

This sounds more like a hardware problem. Code normally does not affect communication.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2011, 21:12
jwakeman jwakeman is offline
Registered User
FRC #0063 (Red Barons)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: 16510
Posts: 182
jwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nicejwakeman is just really nice
Re: Autonomous Not Working

I notice you are setting the expiration time for your motor controllers to 5ms. Any reason to use this instead of the default time of 100ms? Otherwise just comment portions out till you find out what is killing you.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2011, 23:14
mandrews281 mandrews281 is offline
Registered User
FRC #0281
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Greenville SC
Posts: 82
mandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to beholdmandrews281 is a splendid one to behold
Re: Autonomous Not Working

Perhaps I was burned by it too much last year, but isn't the watchdog active by default? It will not get fed with the calls to Wait().
__________________
Michael Andrews
Team #281 Programming Mentor
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