View Single Post
  #15   Spotlight this post!  
Unread 11-06-2009, 00:10
ExarKun666's Avatar
ExarKun666 ExarKun666 is offline
Ben Error/MC Ben/NC Ben
AKA: Ben Kellogg
FRC #2429 (LCEC)
Team Role: Programmer
 
Join Date: Dec 2007
Rookie Year: 2008
Location: La Caņada, CA
Posts: 208
ExarKun666 is an unknown quantity at this point
Send a message via AIM to ExarKun666 Send a message via MSN to ExarKun666 Send a message via Yahoo to ExarKun666
Re: Recording with the Camera

Okay I'm not sure about this code in the PCVideoServer, so if you could give it a glance over tell me any fixes that are apparent to you, it would be great.

NOTE: Look for the line:
//----------------------INSERTED CAMERA CODE----------------------
Those are the places I put the camera code, I put it in 3 times: Once outside
my infinite while loop [used for a momentary switch], and two times in the infinite while loop once when the button state of the trigger = 1 and once when the button state of the trigger = 0. Please look at the insertion points, and tell me of any corrections that need to be made. [Side Note: I just copied the code out of RobotMain() in the CamertoDashboardExample.

Code:
#include "WPILib.h"

#include "vxWorks.h" 

#include "AxisCamera.h" 
#include "BaeUtilities.h"
#include "FrcError.h"
#include "PCVideoServer.h"
#include "SimpleRobot.h"

class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system

	Joystick leftstick; //left joystick initialization

	Joystick rightstick; //right joystick initialization

	Jaguar roller_left; //Jaguar inittialization for left roller SC

	Jaguar roller_right; //Jaguar inittialization for right roller SC
                                                               
	Victor elevator_left; //Victor inittialization for left elevator SC

	Victor elevator_right; //Victor initialization for right elevator SC

	Servo servo_left; //Servo initializtion for the left servo
 
	Servo servo_right; //Servo intializtion for the right servo

 
	
public:
	RobotDemo(void):
		myRobot(1, 2),	// these must be initialized in the same order
		leftstick(1),
		rightstick(2),
		roller_left(3),
		roller_right(4),
		elevator_left(5),
		elevator_right(6),
		servo_left(7),
		servo_right(8)
	{
		GetWatchdog().SetExpiration(100);
	}

		
	void OperatorControl(void)
	{
		GetWatchdog().SetEnabled(true);
		GetWatchdog().Feed();
	// sets all the button states
		unsigned char ball_button_state = 1;
		unsigned char elevator = 1;
		
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			roller_left.Set(1.0);
			roller_right.Set(-1.0);
			elevator_left.Set(-0.35);
		    elevator_right.Set(0.35);
			//Elevator on off button		
//------------------INSERTED CAMERA CODE-----------------------
		    SetDebugFlag ( DEBUG_SCREEN_ONLY  ) ;
			/* start camera task */
			if (StartCameraTask(13, 0, k320x240, ROT_0) == -1) {
				dprintf( LOG_ERROR,"Failed to spawn camera task; exiting. Error code %s", 
						GetVisionErrorText(GetLastVisionError()) );
			}
			dprintf(LOG_DEBUG,"Waiting for camera to initialize");
			Wait(2.0);

			// start up the task serving images to PC
			dprintf(LOG_DEBUG,"Starting image server");
			PCVideoServer pc;
			dprintf(LOG_DEBUG,"Image server Running");

			// this code demonstates stopping and restarting the PC image server
			Wait(60.0);

			dprintf(LOG_DEBUG, "Stopping image server");
			pc.Stop();   
			Wait(10.0);

			dprintf(LOG_DEBUG, "Starting image server again");
			pc.Start();
			Wait(999.0);

			dprintf(LOG_DEBUG, "Stopping image server");
			StopImageToPCServer();   //can use c or cpp call to stop

			dprintf(LOG_DEBUG, "CameraToDashboardExample ending");
//-----------------------------------------------------------
			if(leftstick.GetRawButton(6) != elevator)
			{
				if(leftstick.GetRawButton(6) == 1)
				{
						elevator_left.Set(0.0);
						elevator_right.Set(0.0);
						roller_left.Set(0.0);
						roller_right.Set(0.0);
				}
				else
				{
					elevator_left.Set(-0.35);
					elevator_right.Set(0.35);
					roller_left.Set(1.0);
					roller_right.Set(-1.0);
				}
				elevator = leftstick.GetRawButton(6);
			}
		
				
	//hold trigger to release balls, let go to bring string back up
			while(rightstick.GetRawButton(1) != ball_button_state)
			{
				GetWatchdog().Feed();
				myRobot.TankDrive(-leftstick.GetY(), -rightstick.GetY());
				//starts an infinite while loop to have a mometary switch
				//so all code needs to be put in the loop since it never breaks out
				while(rightstick.GetRawButton(1) == 1)
				{
					GetWatchdog().Feed();
//----------------------INSERTED CAMERA CODE----------------------
					SetDebugFlag ( DEBUG_SCREEN_ONLY  ) ;
					/* start camera task */
					if (StartCameraTask(13, 0, k320x240, ROT_0) == -1) {
						dprintf( LOG_ERROR,"Failed to spawn camera task; exiting. Error code %s", 
								GetVisionErrorText(GetLastVisionError()) );
					}
					dprintf(LOG_DEBUG,"Waiting for camera to initialize");
					Wait(2.0);

					// start up the task serving images to PC
					dprintf(LOG_DEBUG,"Starting image server");
					PCVideoServer pc;
					dprintf(LOG_DEBUG,"Image server Running");

					// this code demonstates stopping and restarting the PC image server
					Wait(60.0);

					dprintf(LOG_DEBUG, "Stopping image server");
					pc.Stop();   
					Wait(10.0);

					dprintf(LOG_DEBUG, "Starting image server again");
					pc.Start();
					Wait(999.0);

					dprintf(LOG_DEBUG, "Stopping image server");
					StopImageToPCServer();   //can use c or cpp call to stop

					dprintf(LOG_DEBUG, "CameraToDashboardExample ending");
//-----------------------------------------------------------------------------
					//if button is pressed realease balls if angles below met
					
						servo_right.SetAngle(0);
						servo_left.SetAngle(180);
						myRobot.TankDrive(-leftstick.GetY(), -rightstick.GetY());
						roller_left.Set(1.0);
						roller_right.Set(-1.0);
						elevator_left.Set(-0.35);
						elevator_right.Set(0.35);
						
	
		
						if(leftstick.GetRawButton(6) != elevator)
						{
							if(leftstick.GetRawButton(6) == 1)
							{
									elevator_left.Set(0.0);
									elevator_right.Set(0.0);
									roller_left.Set(0.0);
									roller_right.Set(0.0);
							}
							else
							{
								elevator_left.Set(-0.35);
								elevator_right.Set(0.35);
								roller_left.Set(1.0);
								roller_right.Set(-1.0);
							}
							elevator = leftstick.GetRawButton(6);
						}
				
		
					
		 		    while(rightstick.GetRawButton(1) == 0)
					{
		 		    		GetWatchdog().Feed();
	//----------------------INSERTED CAMERA CODE----------------------
						SetDebugFlag ( DEBUG_SCREEN_ONLY  ) ;
						/* start camera task */
						if (StartCameraTask(13, 0, k320x240, ROT_0) == -1) {
							dprintf( LOG_ERROR,"Failed to spawn camera task; exiting. Error code %s", 
									GetVisionErrorText(GetLastVisionError()) );
						}
						dprintf(LOG_DEBUG,"Waiting for camera to initialize");
						Wait(2.0);
	
						// start up the task serving images to PC
						dprintf(LOG_DEBUG,"Starting image server");
						PCVideoServer pc;
						dprintf(LOG_DEBUG,"Image server Running");
	
						// this code demonstates stopping and restarting the PC image server
						Wait(60.0);
	
						dprintf(LOG_DEBUG, "Stopping image server");
						pc.Stop();   
						Wait(10.0);
	
						dprintf(LOG_DEBUG, "Starting image server again");
						pc.Start();
						Wait(999.0);
	
						dprintf(LOG_DEBUG, "Stopping image server");
						StopImageToPCServer();   //can use c or cpp call to stop
	
						dprintf(LOG_DEBUG, "CameraToDashboardExample ending");
	//-----------------------------------------------------------------------------
							servo_right.SetAngle(180);
							servo_left.SetAngle(0);
							myRobot.TankDrive(-leftstick.GetY(), -rightstick.GetY());
							roller_left.Set(1.0);
							roller_right.Set(-1.0);
							elevator_left.Set(-0.35);
							elevator_right.Set(0.35);
			
				
							if(leftstick.GetRawButton(6) != elevator)
							{
								if(leftstick.GetRawButton(6) == 1)
								{
										elevator_left.Set(0.0);
										elevator_right.Set(0.0);
										roller_left.Set(0.0);
										roller_right.Set(0.0);
								}
								else
								{
									elevator_left.Set(-0.35);
									elevator_right.Set(0.35);
									roller_left.Set(1.0);
									roller_right.Set(-1.0);
								}
								elevator = leftstick.GetRawButton(6);
							}
				
						if(rightstick.GetRawButton(1) == 1){
							break;
						}
					}
				}
				
				ball_button_state = rightstick.GetRawButton(1);
			} 	 
			GetWatchdog().Feed();
//All the possible drives with 2 joysticks, and 2 speed controllers
		  
			myRobot.TankDrive(-leftstick.GetY(), -rightstick.GetY());
		}
	}
};


START_ROBOT_CLASS(RobotDemo);
__________________
Ben Kellogg




Team Sites: [LCEC Site] [FRC/FLL Site] [LCEC Blog]
Reply With Quote