Help with PSoC board programming please

the website doesnt show where in the code to put “DriverStation::GetDigitalIn”

The GetDigitalIn would be somewhere in your Teleop loop (before you need the data of course)

what data?

The value of the switch…

how do you make the PSoC board communicate with the driver station, i plugged it in but the driver station says:

“I/O unit not detected or not installed correctly.”

Did you follow the steps in section 2.11 of the control system manual for configuring the I/O module?

yes, the driver station sees it now but the driver station still shows:

“I/O unit not detected or not installed correctly.”

HOW DO YOU INTRODUCE THE PSoC BOARD TO THE PROGRAM

(sorry for so much questions, but im just learning)

Does the I/O light turn green in the Diagnostcs window?

Make sure you have the latest update to the DS software (1.2 I believe). You may need to uninstall and reinstall the Cypress software through the updater

yes, it turns green now on the driver station, but im wondering, do i have to introduce it to the code in class and public, or just go ahead in teleoperated and put “DriverStation::GetDigitalIn”??

To use the DriverStation functions, you have to create a DriverStation pointer and set it with DriverStation::GetInstance(). You can then use GetDigitalIn only on the first 8 pins. The DS must also be set to Compatible I/O mode (through I/O screen). If you want to use any of the advanced functionality available through the PSoC board, the system is a bit different (will show with code)

Using DriverStation

public:
...
DriverStation *ds;
...
MyRobot() {
...
ds = DriverStation::GetInstance()
...
}

Teleop() {
...
switch = ds->GetDigitalIn(1);
...
}

Using DriverStationEnhancedIO:

Teleop() {
DriverStationEnhancedIO& dsio = DriverStation::GetInstance()->GetEnhancedIO();
...
switch = dsio.GetDigital(1);
...
}

IMO you should use the DriverStationEnhancedIO version since you can have more control over the PSoC (pulled high/pulled low, input/output, encoder support, LEDs)

for the first one, would the operator code look like this:

  
void operator control
switch  (ds->GetDigitalIn(1));
            {
            	motor->Set(0.0);
            	Wait(1.0);
            	motor->Set(0.0);
            }

i took out the = sign because every time i build it i get an error saying: "expected before = token, how can i fix this??,
and i tried the enhanced io but it gives me a warning that “dsio” is a unused varible

switch is a bool variable. Did you declare it? dsio being unused is an effect of the = error because the compiler doesn’t recognize that line as valid, so no go on using it.

Also, the logic on your version is bad. My version was writing the value of the digital in to a variable. Yours is using that value in a switch statement, which is used when you have different values to run between (a fancy if statement pretty much). Additionally, you are ending the switch without any code because of the ; at the end of the line. You then go onto write a block of code that will execute on every loop. Plus you throw a wait in there. not good. It will compile, but most likely will not run.

This is what I think you want:

void OperatorControl() {
DriverStationEnhancedIO &dsio = DriverStation::GetInstance()->GetEnhancedIO();
// moar code
if (dsio.GetDigital(1)) {
motor->Set(1.0);
Wait(1.0);
motor->Set(0.0);
}

Now, onto what you are actually doing. Assuming this is executing in the same task as the rest of the teleop code, by flipping the switch you are locking up the robot’s controls for a whole second. That means you have no control over the robot for that second. And if you don’t release the switch before the next loop of OperatorControl, you will be stuck for another second without control (this system usually loops on the order of milliseconds assuming no camera code). Also, if you are using the watchdog (which, considering what this code would do, I really hope you are), once you hit this code the watchdog will starve until the beginning of the next loop (or whenever you feed it).

If you absolutely need the 1 second run of the motor, I suggest you export the code for this to another task and communicate via a class variable

Remember that switch is a reserved word in C++. Don’t try to use it for a variable name.

another problem is when i use

DriverStationEnhancedIO &dsio = DriverStation::GetInstance()->GetEnhancedIO();

i get the warning that “dsio” is an undeclared variable

any one knows how to fix this problem?

Try it without the “&” character.

i did that but I build it, i get an error this time

You’re probably trying to use the variable outside of the scope it was declared. Is that code from your init function?

I do not know what do you mean by init code?, I put it under teleoperated

init as in the constructor function (possibly called RobotDemo)

Can you post your full code? Also does it say the error is on the same line as the line you posted?

#include “WPILib.h”
#include “DriverStation.h”
//#include “Vision/HSLImage.h”
//#include “Vision/AxisCamera.h”

/*

  • This is a demo program showing the use of the RobotBase class.
  • The SimpleRobot class is the base of a robot application that will automatically call your
  • Autonomous and OperatorControl methods at the right time as controlled by the switches on
  • the driver station or the field controls.
    */
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    /// CLASS ///

class RobotDemo : public SimpleRobot
{
Victor *VictorPair1, *VictorPair2;
RobotDrive *myRobot; // robot drive system
Joystick *RightStick, *LeftStick, *ThirdStick; // only joystick
DriverStation *ds, *dsio; // driver station
Servo *Left_GearServo, *Right_GearServo;
Victor *Dribbler, *CamKicker, *Winch;
DigitalInput *limitSwitchB, *AutoSwitch1, *AutoSwitch2, *AutoSwitch3, *Swltch;
Relay *ArmRelease;
// AxisCamera *camera;

//////////////////////////////////////////////////////////////////////////////////////////////////////
/// PUBLIC ///

public:

RobotDemo(void)
{  
	VictorPair1 = new Victor(1);
    VictorPair2 = new Victor(2);
    ds = DriverStation::GetInstance();
    myRobot = new RobotDrive(VictorPair1, VictorPair2); // create robot drive base
    
    
    RightStick = new Joystick(1);// create the joysticks
    LeftStick = new Joystick(2);
    ThirdStick = new Joystick(3);
    
    
	AutoSwitch1 = new DigitalInput(1);
	AutoSwitch2 = new DigitalInput(2);
	AutoSwitch3 = new DigitalInput(3);
    limitSwitchB = new DigitalInput(7);
    
    
    
    Left_GearServo = new Servo(3);
    Right_GearServo = new Servo(4);
    
    
    Dribbler = new Victor(5);
    CamKicker = new Victor(6);
    Winch = new Victor(7);
    
    
    ArmRelease = new Relay(1);

    

    GetWatchdog().SetExpiration(100);        
}   

///////////////////////////////////////////////////////////////////////////////////////////////////////
/// AUTONOMOUS FIRST ZONE ///

void Autonomous(void)
{   
    GetWatchdog().SetEnabled(false);
  
    {
    	{
    		Right_GearServo->Set(127);
    		Left_GearServo->Set(127);
    	}
    	

    	  if (AutoSwitch1->Get()== 1)
    	  {	  
    		  {
    	      myRobot->Drive(-0.5, 0.0);
    	      Dribbler->Set(1.0);
    	      Wait(1.5);
    	      myRobot->Drive(0.0, 0.0);
    		  CamKicker->Set(-1.0);
    		  Wait(1.0);
    		  CamKicker->Set(0.0);
    		  Dribbler->Set(0.0);
    		  	while(limitSwitchB->Get()== 0)
    		  	{
    		  		CamKicker->Set(-1.0);
    		  	}
    		  }
    	  	  if (limitSwitchB->Get()== 1)
    	  	  {
    	  		  CamKicker->Set(0.0);
    	  	  }
    	  };

////////////////////////////////////////////////////////////////////////////////////////
//////SECOND ZONE/////

   	  if (AutoSwitch2->Get()==1)
    	    {
    		  {
    	      myRobot->Drive(-0.30, 0.0);
    	      Dribbler->Set(1.0);
    	      Wait(2.6);
    	      myRobot->Drive(0.0, 0.0);
    		  CamKicker->Set(-1.0);
    		  Wait(1.0);
    		  CamKicker->Set(0.0);
    		  Dribbler->Set(0.0);
    		  	while(limitSwitchB->Get()== 0)
    		  	{
    		  		CamKicker->Set(-1.0);
    		  	}
    	    }
    	  if (limitSwitchB->Get()== 1)
    	  {
    		  CamKicker->Set(0.0);
    	  }
		  {
	      myRobot->Drive(-0.30, 0.0);
	      Dribbler->Set(1.0);
	      Wait(1.2);
	      myRobot->Drive(0.0, 0.0);
		  CamKicker->Set(-1.0);
		  Wait(1.0);
		  CamKicker->Set(0.0);
		  Dribbler->Set(0.0);
		  	while(limitSwitchB->Get()== 0)
		  	{
		  		CamKicker->Set(-1.0);
		  	}
	    }
	  if (limitSwitchB->Get()== 1)
	  {
		  CamKicker->Set(0.0);
	  }
   		  
    	    };

////////////////////////////////////////////////////////////////////////////////
//////THIRD ZONE//////
if (AutoSwitch3->Get()== 1)
{
{
myRobot->Drive(-0.30, 0.0);
Dribbler->Set(1.0);
Wait(1.3);
myRobot->Drive(0.0, 0.0);
CamKicker->Set(-1.0);
Wait(1.0);
CamKicker->Set(0.0);
Dribbler->Set(0.0);
while(limitSwitchB->Get()== 0)
{
CamKicker->Set(-1.0);
}
}
if (limitSwitchB->Get()== 1)
{
CamKicker->Set(0.0);
}
{
myRobot->Drive(-0.30, 0.0);
Dribbler->Set(1.0);
Wait(1.2);
myRobot->Drive(0.0, 0.0);
CamKicker->Set(-1.0);
Wait(1.0);
CamKicker->Set(0.0);
Dribbler->Set(0.0);
while(limitSwitchB->Get()== 0)
{
CamKicker->Set(-1.0);
}
}
if (limitSwitchB->Get()== 1)
{
CamKicker->Set(0.0);
}
{
myRobot->Drive(-0.30, 0.0);
Dribbler->Set(1.0);
Wait(1.3);
myRobot->Drive(0.0, 0.0);
CamKicker->Set(-1.0);
Wait(1.0);
CamKicker->Set(0.0);
Dribbler->Set(0.0);
while(limitSwitchB->Get()== 0)
{
CamKicker->Set(-1.0);
}
}
if (limitSwitchB->Get()== 1)
{
CamKicker->Set(0.0);
}
{
myRobot->Drive(1.0, 0.0);
Wait(0.5);
myRobot->Drive(0.0, 0.0);
}

  	  	  }
  		
  	  };
      };

//////////////////////////////////////////////////////////////////////////////////////////////
/// OPERATOR CONTROL ///
void OperatorControl(void)
{

    GetWatchdog().SetEnabled(false);
    //GetWatchdog().Feed(); 
  DriverStationEnhancedIO &dsio = DriverStation::GetInstance()->GetEnhancedIO();


    
    
   
   /* while (IsOperatorControl())
    {         
    AxisCamera &camera = AxisCamera::GetInstance();
    camera.WriteResolution(AxisCamera::kResolution_640x480);
    camera.WriteCompression(20);
    camera.WriteBrightness(0);  
    }*/
     // Assume that the THIRDSTICK THROTTLE is initially set at 100%  (max)
     // float Max_DribblerSpeed = ThirdStick->GetThrottle();

/////////////////////////////////////////////////////////////////////////////////////////////
/// Robot Drive ///

    while (IsOperatorControl())
    {    
        myRobot->TankDrive(RightStick, LeftStick); 

///////////////////////////////////////////////////////////////////////////////////////////
/// Dribbler Control ///

         if (ThirdStick->GetRawButton(2))
         {  
          Dribbler->Set(1.0);
         };  

//////////////////////////////////////////////////////////////////////////////////////////
/// ARM CONTROL ///

   /// ARM RELEASE ///

   if (ThirdStick->GetRawButton(6)) 
   {
       ArmRelease->Set(Relay::kForward);
       Winch->Set(0.0);
       Dribbler->Set(0.0);
       CamKicker->Set(0.0);
   } 
   else if (ThirdStick->GetRawButton(7))
   {
       ArmRelease->Set(Relay::kReverse);
       Winch->Set(0.0);
       Dribbler->Set(0.0);
       CamKicker->Set(0.0);
   } 
   else 
   {
       ArmRelease->Set(Relay::kOff);
   }

	/// WINCH ///

   if (ThirdStick->GetRawButton(11)) 
   {
       Winch->Set(1.0);
       CamKicker->Set(0.0);
       Dribbler->Set(0.0);
       ArmRelease->Set(Relay::kOff);
   } 
   else if (ThirdStick->GetRawButton(10))
   {
       Winch->Set(-1.0);
       CamKicker->Set(0.0);
       Dribbler->Set(0.0);
       ArmRelease->Set(Relay::kOff);
   } 
   else 
   {
       Winch->Set(0.0);
   }

/////////////////////////////////////////////////////////////////////////////////////////////////////
/// CAMKICKER && LIMITSWITCH-B ///

 if(ThirdStick-> GetRawButton(4)) 
 {
   while (limitSwitchB->Get()== 0)
   		{
	   		CamKicker->Set(-1.0);
			Dribbler->Set(0.0);
	        Winch->Set(0.0);
	        ArmRelease->Set(Relay::kOff);
   		}
   CamKicker->Set(0.0);
 }
  

 if (ThirdStick->GetTrigger() && (limitSwitchB->Get()== 1))
  {
     CamKicker->Set(-1.0);
     Winch->Set(0.0);
     Dribbler->Set(0.0);
     ArmRelease->Set(Relay::kOff);

 if (limitSwitchB->Get() == 0)
  {
        	CamKicker->Set(0.0);
   }

}

/////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
/// GEAR CONTROL ///

    if ( (LeftStick->GetTrigger()) )                                      
            {
    	Left_GearServo -> Set(127);
    	Right_GearServo -> Set(127);
            };
    
    if ( (RightStick->GetTrigger()) )                                      
             {
    	Left_GearServo ->Set(-127);
    	Right_GearServo ->Set(-127);
             };       	
    
    };
};

};

START_ROBOT_CLASS(RobotDemo);