Disclaimer: I am not a programmer, I am a builder who took the robot home for break who wants to test it.
This is the code that we had for our original clamp which was a single acting cylinder. However, I rebuilt it to a double acting cylinder and now nothing happens in the program. I have searched all over the forums and can’t figure out what is wrong with this. Im also aware that you all will likely need to see more of my code, and I can post it as needed. I’m grateful for any help.
The code for single and double acting solenoids is the same and your code seems to be fine.
Here’s a list of your potential problems starting with the most likely:
- Wrong Port - Double check which port the solenoid is on and which port the program has it on
- Bad driver cable - You can check this by looking for any frays in the cable
- No air
- Bad solenoid
I have both the correct port and tested it with an LED.
I replaced the cable multiple times
I had the air tank filled up when testing
I replaced the solenoid with a brand new one.
Still no luck unfortunately.
Could you share the part of the code where you are defining the Pneumatics
?
Yes, that all seems to be correct. Are you running your if statements in a while loop?
There is a while encompassing all of the driver controls
Seems like your code isnt correct, you can find the link to the vexcode API here
.set(true or false) does not seem to be there so i would suggest trying
.open(); or .close();
Hope this helps.
They are using a digital_out
instead of pneumatics
. It is correct for digital_out
. Here is the api docs:
https://api.vexcode.cloud/v5/class/classvex_1_1digital__out
Could you please post your entire usercontrol code? It looks like everything you posted so far is correct. The issue might lie elsewhere.
while (1) {
//Drivetrain code
LDrive.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)+Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
RDrive.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)-Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
LDrive2.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)+Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
RDrive2.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)-Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
//Control for four bar
if(Controller1.ButtonL1.pressing()){
LeftLift.spin(directionType::rev, 100, velocityUnits::pct);
RightLift.spin(directionType::rev, 100, velocityUnits::pct);
}
else if(Controller1.ButtonL2.pressing()){
RightLift.spin(directionType::fwd, 100, velocityUnits::pct);
LeftLift.spin(directionType::fwd, 90,velocityUnits::pct);
}
else{
RightLift.stop(brakeType::hold);
LeftLift.stop(brakeType::hold);
}
//other mogo pickup
if(Controller1.ButtonR1.pressing()){
MGTilterL.spin(directionType::fwd, 100, velocityUnits::pct);
MGTilterR.spin(directionType::fwd, 100, velocityUnits::pct);
}
else if(Controller1.ButtonR2.pressing()){
MGTilterL.spin(directionType::rev, 100, velocityUnits::pct);
MGTilterR.spin(directionType::rev, 100,velocityUnits::pct);
}
else{
MGTilterL.stop(brakeType::hold);
MGTilterR.stop(brakeType::hold);
}
if( Controller1.ButtonX.pressing() ) {
Pneumatics.set( true );
}
//Otherwise don’t activate
if( Controller1.ButtonY.pressing() )
Pneumatics.set( false );
wait(20,msec);
}
}
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
pre_auton();
while (true) {
wait(100, msec);
}
}
I just tested it again with the single acting cylinder and it worked. Beginning to wonder if all of our double-acting solenoid wires are broken or something
I just put your code on my robot and it works perfectly. I think you might just have a bad solenoid or something.
Alright, i will see what I can do. Thanks so much for all of your help!
Here it is if you want to try it:
#include "vex.h"
using namespace vex;
brain Brain;
controller Controller1;
competition Competition;
motor LeftLift(0);
motor RightLift(0);
motor MGTilterL(0);
motor MGTilterR(0);
digital_out Pneumatics(Brain.ThreeWirePort.A);
void usercontrol(){
while (1) {
//Drivetrain code
/*LDrive.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)+Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
RDrive.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)-Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
LDrive2.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)+Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
RDrive2.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct)-Controller1.Axis4.position(percentUnits::pct)/2-Controller1.Axis2.position(percentUnits::pct), velocityUnits::pct);
//Control for four bar*/
if(Controller1.ButtonL1.pressing()){
LeftLift.spin(directionType::rev, 100, velocityUnits::pct);
RightLift.spin(directionType::rev, 100, velocityUnits::pct);
}
else if(Controller1.ButtonL2.pressing()){
RightLift.spin(directionType::fwd, 100, velocityUnits::pct);
LeftLift.spin(directionType::fwd, 90,velocityUnits::pct);
}
else{
RightLift.stop(brakeType::hold);
LeftLift.stop(brakeType::hold);
}
//other mogo pickup
if(Controller1.ButtonR1.pressing()){
MGTilterL.spin(directionType::fwd, 100, velocityUnits::pct);
MGTilterR.spin(directionType::fwd, 100, velocityUnits::pct);
}
else if(Controller1.ButtonR2.pressing()){
MGTilterL.spin(directionType::rev, 100, velocityUnits::pct);
MGTilterR.spin(directionType::rev, 100,velocityUnits::pct);
}
else{
MGTilterL.stop(brakeType::hold);
MGTilterR.stop(brakeType::hold);
}
if( Controller1.ButtonX.pressing() ) {
Pneumatics.set( true );
}
//Otherwise don’t activate
if( Controller1.ButtonY.pressing() ){
Pneumatics.set( false );
}
wait(20,msec);
}
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Competition.drivercontrol(usercontrol);
while (true) {
wait(100, msec);
}
}
This code should work properly, make sure you are pressurized and that your solenoid isnt defective (actually had 2 recently that were leaking, fresh out of the package)
After trying half a dozen wires, it ended up working. Caused me a lot of undue stress, but thanks for all the help.