Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Help with PSoC board programming please (http://www.chiefdelphi.com/forums/showthread.php?t=85676)

krudeboy51 04-05-2010 16:35

Help with PSoC board programming please
 
can any one please show me how to program a PSoC board with a switch
or give me a sample code??
Quote:

class:
???
public:
??????
Void operator control:
???

Andrew Schreiber 04-05-2010 16:41

Re: Help with PSoC board programming please
 
http://www.virtualroadside.com/WPILi...r_station.html

I have linked the relevant API documents. You can use DriverStation::GetDigitalIn([number]) to get the value of the switch.

And PLEASE try to take a little more time writing your posts in the future.

krudeboy51 04-05-2010 20:56

Re: Help with PSoC board programming please
 
Quote:

Originally Posted by Andrew Schreiber (Post 960141)
http://www.virtualroadside.com/WPILi...r_station.html

I have linked the relevant API documents. You can use DriverStation::GetDigitalIn([number]) to get the value of the switch.

And PLEASE try to take a little more time writing your posts in the future.

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

Radical Pi 04-05-2010 23:34

Re: Help with PSoC board programming please
 
The GetDigitalIn would be somewhere in your Teleop loop (before you need the data of course)

krudeboy51 05-05-2010 06:12

Re: Help with PSoC board programming please
 
Quote:

Originally Posted by Radical Pi (Post 960224)
The GetDigitalIn would be somewhere in your Teleop loop (before you need the data of course)

what data?

Radical Pi 05-05-2010 09:59

Re: Help with PSoC board programming please
 
The value of the switch...

krudeboy51 05-05-2010 12:20

Re: Help with PSoC board programming please
 
how do you make the PSoC board communicate with the driver station, i plugged it in but the driver station says:
Quote:

"I/O unit not detected or not installed correctly."

Joe Ross 05-05-2010 13:12

Re: Help with PSoC board programming please
 
Did you follow the steps in section 2.11 of the control system manual for configuring the I/O module?

krudeboy51 05-05-2010 15:12

Re: Help with PSoC board programming please
 
Quote:

Originally Posted by Joe Ross (Post 960305)
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:

Quote:

"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)

Radical Pi 05-05-2010 18:46

Re: Help with PSoC board programming please
 
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

krudeboy51 05-05-2010 20:58

Re: Help with PSoC board programming please
 
Quote:

Originally Posted by Radical Pi (Post 960362)
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"??

Radical Pi 05-05-2010 23:15

Re: Help with PSoC board programming please
 
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
Code:

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

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

Using DriverStationEnhancedIO:
Code:

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)

krudeboy51 06-05-2010 17:16

Re: Help with PSoC board programming please
 
for the first one, would the operator code look like this:
Code:

 
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

Radical Pi 06-05-2010 19:42

Re: Help with PSoC board programming please
 
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:
Code:

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

Joe Ross 06-05-2010 19:59

Re: Help with PSoC board programming please
 
Quote:

Originally Posted by Radical Pi (Post 960655)
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.

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


All times are GMT -5. The time now is 13:38.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi