Go to Post Paul Copioli - A guy who is 13 years older than me, but acts about 13 years younger. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-02-2011, 16:04
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Compressor programming please help

Ok so i was reading the rule book and the pressure switch is supposed to start working at 115 PSI and turn back on at 95. The rule books says the cRIO must be programmed to react to the GPIO port that is connected to the pressure switch... The question is... what is a GPIO port?????

This is also my program for the compressor please tell me why this dosnt work please! i have no clue why.

#include "Compressor.h"

Relay compressor;
DigitalInput compressor_switch;

compressor(5),
compressor_switch(1),

if(compressor_switch.Get() == 1) {
compressor.Set(Relay::kOn);
sprintf(m_compressor, "Comressors is Off;");
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
lcd->UpdateLCD();
} else {
compressor.Set(Relay::kOff);
sprintf(m_compressor, "Comressors is On.");
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
lcd->UpdateLCD();
}
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2011, 16:13
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

also, what PWM wires have to connected to the compressor pressure switch? Black & Red or Red & white or Black & White and does it matter which side of the pressure switch is each wire supposed to be on or it doesn't matter?
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2011, 16:20
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Compressor programming please help

The Compressor class takes care of all the logic for you. All you need to do is create a Compressor object with the proper Relay and Digital I/O pins specified, and tell it to start.

Code:
Compressor *myCompressor = new Compressor(1, 5); 
myCompressor->Start();
It will turn on and off all by itself after that.

The pressure switch is a simple SPST switch. It does not matter which side of the connection is which. One side goes to a black "ground" wire on a Digital I/O, and the other side goes to a white "signal" wire. The red "+5" wire should not be connected, and for safety the end of it should be wrapped in electrical tape to prevent it from touching anything.

Last edited by Alan Anderson : 02-02-2011 at 16:22.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-02-2011, 18:50
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

ok this is my whole code..


#include "WPILib.h"
#include "Vision/AxisCamera.h"
#include "Vision/HSLImage.h"
#include "DriverStationLCD.h"
//#include "AxisCamera.h"
//#include "FrcError.h"
#include "Vision/PCVideoServer.h"
#include "Compressor.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 RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick leftjoy;
Joystick rightjoy;
Joystick armjoy;
Jaguar arm;
Relay piston;
Relay compressor;
DigitalInput compressor_switch;
DigitalInput limitswitch_foward;
DigitalInput limitswitch_reverse;
Servo x_axis;
Servo y_axis;
public:
RobotDemo(void):
myRobot(1, 2),
leftjoy(1),
rightjoy(2),
armjoy(3),
arm(3),
piston(4),
compressor(5),
compressor_switch(1),
limitswitch_foward(2),
limitswitch_reverse(3),
x_axis(10),
y_axis(9)
{
GetWatchdog().SetExpiration(1.00);
}
/*
*
* Drive left & right motors for 3 seconds then stop
*/
void Autonomous(void)
{
/*PCVideoServer * pyrocam = new PCVideoServer();
pyrocam->Start();*/
//AxisCamera &camera = AxisCamera::GetInstance(); // Creates an instance of the camera
// camera.
//AxisCamera &camera = AxisCamera::getInstance();
/*
x_axis.SetAngle(90);
y_axis.SetAngle(90);*/
GetWatchdog().SetEnabled(false);
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
DriverStationLCD * lcd = DriverStationLCD::GetInstance();
// drive with arcade style (use right stick)
int clawclosebutton = 2;
float speedModifier = 1.00;
float armModifier = 0.75;
char m_motor[22];
char m_compressor[22];
char m_lim_switch[22];
char m_piston[22];
//LMV = Left Motor Value; RMV = Right Motor Value
sprintf(m_motor, "LMV: %f; RMV: %f;", leftjoy.GetY() * speedModifier, rightjoy.GetY() * speedModifier);
lcd->Printf(DriverStationLCD::kUser_Line1, 1, m_motor);
myRobot.TankDrive(leftjoy.GetY() * speedModifier, rightjoy.GetY() * speedModifier);
//myRobot.SetLeftRightMotorSpeeds(leftjoy.GetY() * speedModifier, rightjoy.GetY() * speedModifier);
//Compressor Operation
/* if(compressor_switch.Get() == 1) {
compressor.Set(Relay::kOff);
sprintf(m_compressor, "Comressors is Off;");
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
lcd->UpdateLCD();
} else {
compressor.Set(Relay::kOn);
sprintf(m_compressor, "Comressors is On.");
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
lcd->UpdateLCD();
}
*/
//if (rightjoy.GetRawButton(compressoronbutton) == 1) {
/* if(leftjoy.GetTrigger() == 1) {
//compressor.Set(Relay:
compressor.Set(Relay::kOff);
compressor.SetDirection(Relay::kForwardOnly);
sprintf(m_compressor, "Comressors is On.");
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
} else {
compressor.Set(Relay::kOn);
sprintf(m_compressor, "Comressors is Off.");
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
}
*/
compressor.Set(Relay::kOn);
//Arm operation
//Do not forget to include sensors,
//The following program is temporary.
/*if ((limitswitch_foward.Get() ==1) && (armjoy.GetY() > 0)) {
sprintf(m_lim_switch, "Front Switch Triggered.");
lcd->Printf(DriverStationLCD::kUser_Line3, 1, m_lim_switch);
arm.Set(0.0);
} else if ((limitswitch_reverse.Get() ==1) && (armjoy.GetY()< 0)) {
sprintf(m_lim_switch, "Rear Switch Triggered.");
lcd->Printf(DriverStationLCD::kUser_Line3, 1, m_lim_switch);
arm.Set(0.0);
} else{*/
sprintf(m_lim_switch, "Arm Y-Axis: %f", armjoy.GetY());
lcd->Printf(DriverStationLCD::kUser_Line3, 1, m_lim_switch);
arm.Set(armjoy.GetY() * armModifier);
//}
//Piston operation
if (armjoy.GetTrigger() == 1) {
sprintf(m_piston, "Arm: Clamped");
lcd->Printf(DriverStationLCD::kUser_Line4, 1, m_piston);
piston.SetDirection(Relay::kForwardOnly);
piston.Set(Relay::kOn);
} else if (armjoy.GetRawButton(clawclosebutton) == 1) {
sprintf(m_piston, "Arm: Opened");
lcd->Printf(DriverStationLCD::kUser_Line4, 1, m_piston);
piston.SetDirection(Relay::kReverseOnly);
piston.Set(Relay::kOn);
} else {
sprintf(m_piston, "Arm: Off");
lcd->Printf(DriverStationLCD::kUser_Line4, 1, m_piston);
piston.Set(Relay::kOff);
}
lcd->UpdateLCD();
/* HSLImage image; // Creates an image
AxisCamera &camera = AxisCamera::GetInstance(); // Creates an instance of the camera
camera.WriteResolution(AxisCameraParams::kResoluti on_160x120);
camera.WriteBrightness(0);
camera.GetImage(image.GetImaqImage()); // Gets the image from the camera
Wait(5.00); // wait for a motor update time {
*/
}
}
};
START_ROBOT_CLASS(RobotDemo);


Its not turning on the compressor for some reason by it self =/ any problems you can see in my code?
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #5   Spotlight this post!  
Unread 02-02-2011, 18:54
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

this is is more relevant.. not as messy


#include "WPILib.h"
#include "Vision/AxisCamera.h"
#include "Vision/HSLImage.h"
#include "DriverStationLCD.h"
//#include "AxisCamera.h"
//#include "FrcError.h"
#include "Vision/PCVideoServer.h"
#include "Compressor.h"

class RobotDemo : public SimpleRobot
{

RobotDrive myRobot; // robot drive system
Joystick leftjoy;
Joystick rightjoy;
Joystick armjoy;
Jaguar arm;
Relay piston;
Relay compressor;
DigitalInput compressor_switch;
DigitalInput limitswitch_foward;
DigitalInput limitswitch_reverse;
Servo x_axis;
Servo y_axis;

myRobot(1, 2),
leftjoy(1),
rightjoy(2),
armjoy(3),
arm(3),
piston(4),
compressor(5),
compressor_switch(1),
limitswitch_foward(2),
limitswitch_reverse(3),
x_axis(10),
y_axis(9)
{
GetWatchdog().SetExpiration(1.00);
}

void OperatorControl(void)

compressor.Set(Relay::kOn);
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #6   Spotlight this post!  
Unread 02-02-2011, 19:00
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Compressor programming please help

Quote:
Originally Posted by Tds123 View Post
this is is more relevant.. not as messy
your constructor does not look the same as Alan's.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-02-2011, 19:17
Trump Trump is offline
Registered User
FRC #2053
 
Join Date: Feb 2010
Location: New York
Posts: 18
Trump is an unknown quantity at this point
Re: Compressor programming please help

Thge compressor has its own class in wpi lib, so you don't have to create a relay for it. Instead you make it a compressor object and construct it with the pressure switch port and the relay port.

so...
Code:
 
 
class
RobotDemo : public SimpleRobot {
RobotDrive myRobot; // robot drive system Joystick leftjoy; Joystick rightjoy; Joystick armjoy; Jaguar arm; Relay piston;
Compressor robot_compressor; // This will handle the compressor
DigitalInput limitswitch_foward; DigitalInput limitswitch_reverse; Servo x_axis; Servo y_axis;
myRobot(1, 2), leftjoy(1), rightjoy(2), armjoy(3), arm(3), piston(4),
robot_compressor(pressure switch channel, relay channel);//obviously sub in the ports that you are using
      void OperatorControl(void) { GetWatchdog().SetExpiration(1.00); robot_compressor.start();// to start the compressor
robot_compressor.stop();//to stop the compressor }


I also moved where the GetWatchdog.SetExperation I think it just got pasted into the wrong spot (it was above the operator control function)

Reply With Quote
  #8   Spotlight this post!  
Unread 02-02-2011, 19:49
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

soo i dont put anything in between
"
robot_compressor.start();

robot_compressor.stop();
}
"
it will just start and stop on its own using the pressure switch?
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #9   Spotlight this post!  
Unread 02-02-2011, 20:23
Trump Trump is offline
Registered User
FRC #2053
 
Join Date: Feb 2010
Location: New York
Posts: 18
Trump is an unknown quantity at this point
Re: Compressor programming please help

Quote:
Originally Posted by Tds123 View Post
soo i dont put anything in between
it will just start and stop on its own using the pressure switch?
Yes you do, put your loops between the start and stop.

You use start when you want the compressor to start controlling itself... it will automatically turn on or off based on if the max pressure is realized.

If for some part of the match you don't want the compressor running no matter what (even if it isn't at max pressure yet) you use stop.

For example if you only wanted to use pneumatics during autonomous you would use start before your autonomous loop, and then after the loop you would tell it to stop so it wouldn't continue to run during teleop.

The start and stop commands don't literally tell the compressor to turn on or turn off, they tell the compressor whether it should be controlling itself or not. I hope this helps.

Last edited by Trump : 02-02-2011 at 20:27.
Reply With Quote
  #10   Spotlight this post!  
Unread 02-02-2011, 20:56
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

ok so how would i write the code to just control it self for all of operator control period no matter what to just shut off at 115 like the pressure switch makes it and to turn back on at 95 and to never shut off completely ... so that it would always turn back on when we need more pressure
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #11   Spotlight this post!  
Unread 02-02-2011, 21:10
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Compressor programming please help

Do you not understand what I wrote in my first response to you? It should be exactly what you need.
Reply With Quote
  #12   Spotlight this post!  
Unread 02-02-2011, 22:12
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

i dont actually, im sorry.. Its because i am fairly new to programming and I know what I am doing most of the time but I don't understand how to insert your program into mine since i tried and it could not build
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
  #13   Spotlight this post!  
Unread 02-02-2011, 22:51
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Compressor programming please help

To control the compressor, you just use the Compressor class. You instantiate a single Compressor object, telling it which relay port is connected to the compressor and which Digital I/O port is connected to the pressure switch. You then call its Start() method.

That's it. Nothing more. You do not create a Relay object for it. You do not create a DigitalInput for it.

Take out everything in your code that you have put in to try to make the compressor work, and replace it with two lines in your initialization code:

Code:
Compressor *myCompressor = new Compressor(1, 5); 
myCompressor->Start();
"1" is the Digital Input with the pressure switch. "5" is the Relay powering the compressor.

You could also make myCompressor a regular variable instead of a pointer and call the object's constructor as part of the RobotDemo constructor, but I'm not as comfortable as some people are with the requirements for what order things have to be specified.
Reply With Quote
  #14   Spotlight this post!  
Unread 02-02-2011, 23:17
Tds123's Avatar
Tds123 Tds123 is offline
There is no I in team =]
AKA: Timothy Shub
FRC #1396 (Pyrobots)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Tottenville High School
Posts: 27
Tds123 is an unknown quantity at this point
Send a message via AIM to Tds123
Re: Compressor programming please help

oh ok thank you, i will try to make this work properly next time i get a change to build on my robot thank you so much
__________________
ThE sCaLeS oF bAlAnCe (Team 1396)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:18.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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