|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
PSoc Java code.
Hello all,
Working on getting the PSoC IO to work with our switches. After flashing and wiring it, it shows up in the Driver station fine. But what do you use to make it work in code (JAVA)? Just some short sample code will be greatly appreciated. Thanks you. |
|
#2
|
|||||
|
|||||
|
Re: PSoc Java code.
A simple snippet to read a digital input:
Code:
DriverStationEnhancedIO m_io = DriverStation.getInstance().getEnhancedIO();
/**
* Get the state of a digital input
* @param which The channel
* @return The state of the digital input
*/
public boolean getDigital(int which) {
try { //You need to catch an exception
return m_io.getDigital(which); //Return the state of the digital input
} catch(Exception e) { //An exception will be thrown if the board is not plugged in
e.printStackTrace(); //If an exception is thrown, print exception data
return false; //and return false
}
}
Hope it helps ![]() If you need help with anything else PSoC related, ask away. We've worked with all features of it in some form or another. Last edited by Jeremy Germita : 24-06-2011 at 22:25. |
|
#3
|
||||
|
||||
|
Re: PSoc Java code.
Hey thanks for the reply. I think we got it.
![]() Also on a side note what happens when you feed a victor .set method with a value greater then 1? Does it just auto round down to 1? |
|
#4
|
|||||
|
|||||
|
Re: PSoc Java code.
Quote:
Code:
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately
* scaling the value for the FPGA.
*
* @param speed The speed value between -1.0 and 1.0 to set.
*/
public void set(double speed) {
setSpeed(speed);
}
Code:
/**
* Set the PWM value based on a speed.
*
* This is intended to be used by speed controllers.
*
* @pre SetMaxPositivePwm() called.
* @pre SetMinPositivePwm() called.
* @pre SetCenterPwm() called.
* @pre SetMaxNegativePwm() called.
* @pre SetMinNegativePwm() called.
*
* @param speed The speed to set the speed controller between -1.0 and 1.0.
*/
final void setSpeed(double speed) {
// clamp speed to be in the range 1.0 >= speed >= -1.0
if (speed < -1.0) {
speed = -1.0;
} else if (speed > 1.0) {
speed = 1.0;
}
// calculate the desired output pwm value by scaling the speed appropriately
int rawValue;
if (speed == 0.0) {
rawValue = getCenterPwm();
} else if (speed > 0.0) {
rawValue = (int) (speed * ((double)getPositiveScaleFactor()) +
((double)getMinPositivePwm()) + 0.5);
} else {
rawValue = (int) (speed * ((double)getNegativeScaleFactor()) +
((double)getMaxNegativePwm()) + 0.5);
}
// send the computed pwm value to the FPGA
setRaw(rawValue);
}
-Jeremy |
|
#5
|
||||
|
||||
|
Re: PSoc Java code.
Cool Thank you.
Can't wait to test this out. ![]() |
|
#6
|
||||
|
||||
|
Re: PSoc Java code.
Update: After running the code netbeans gives this error.
Quote:
|
|
#7
|
|||||
|
|||||
|
Re: PSoc Java code.
That usually means it is not plugged in.
Does the driverstation program show a green light indicator on the "IO" tab? Go into diagnostics and look at a similar indicator next to IO. Another possible cause is that you have flashed the PSoC with incorrect firmware. Make sure you flashed it with the most up to date FRC firmware, not the stock firmware. |
|
#8
|
||||
|
||||
|
Re: PSoc Java code.
Yeah the PSoC is plugged in with a switch, and it shows up and works fine in the driver station I/O Tab.
|
|
#9
|
|||||
|
|||||
|
Re: PSoc Java code.
Strange....
Can you post screenshots of the driverstation(in the diagnostics and IO tabs) and your code? A full log(from cRio boot to where the exception is thrown) would be helpful to see. |
|
#10
|
||||
|
||||
|
Re: PSoc Java code.
Quote:
Also do you know how to kill the robot program within code? |
|
#11
|
|||||
|
|||||
|
Re: PSoc Java code.
I don't see anything out of the ordinary in this log. (Except for the exception.)
I can only tell you it is most likely a hardware issue. Try playing around with different cables, ports and hubs for the PSoC board. Again, verify that it is the most up to date firmware. There is no way to put the robot into the disabled mode from the code. you could however, stop running normal teleop/autonomous code using a simple boolean input. You could put logic like this into your loops: Code:
if(!disabled) {
//Teleop Code here!
} else {
System.out.println("Teleop Code Not Running");
}
|
|
#12
|
||||
|
||||
|
Re: PSoc Java code.
What is the most up to date firmware on the PSoC?
I think I am running v20. I was thinking using the disable mode to kill the robot when it crosses over the line (with line sensors) as a safety feature. The PSoC shows up in the Driverstation I/O fine but still gives me the expectation in console. |
|
#13
|
||||
|
||||
|
Re: PSoc Java code.
Nvm. I just got it to work.
Lol, Under config enchanted has to be checked. x] Thanks for the help. ![]() |
|
#14
|
||||
|
||||
|
Re: PSoc Java code.
Enhanced, not enchanted.
![]() Also, for anyone who's interested, here's a link to my team's PSoC code for this year: https://github.com/prog694/frc/blob/...Interface.java |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|