Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Compressor Code problems (http://www.chiefdelphi.com/forums/showthread.php?t=83922)

Briyanna 06-03-2010 16:15

Compressor Code problems
 
Team 2895
So our team is some what new to the programming thing and we have been having problems with our code. We finally got the compressor declared but when we did that the code came up with another error saying: In member function `virtual void BuiltinDefaultCode::TeleopPeriodic()': 'class Compressor' has no member named 'Set' request for member `Set' in `((BuiltinDefaultCode*)this)->BuiltinDefaultCode::compressor', which is of non-class type `Compressor*'. Now we cant seem to get this error to go away can anyone help us?

Quote:

//*Compressor

if (Joystick(1).GetRawButton(10)) //if button 10 is pressed on joystick 1 compressor will turn on
{
compressor= new Compressor(1, 1);
compressor ->Set(true);
}
if (Joystick(1).GetRawButton(11)) //if button 11 is pressed on joystick 1 compressor will turn off
{
compressor.Set(false);

}

byteit101 06-03-2010 16:40

Re: Compressor Code problems
 
Quote:

Originally Posted by Briyanna (Post 932239)
Team 2895
So our team is some what new to the programming thing and we have been having problems with our code. We finally got the compressor declared but when we did that the code came up with another error saying: In member function `virtual void BuiltinDefaultCode::TeleopPeriodic()': 'class Compressor' has no member named 'Set' request for member `Set' in `((BuiltinDefaultCode*)this)->BuiltinDefaultCode::compressor', which is of non-class type `Compressor*'. Now we cant seem to get this error to go away can anyone help us?

1. Declare the compressor at the top. otherwise, the compressor will be constructed and destructed every loop, so the compressor will only be running for the brief time in the function.

2. use a pointer (Compressor *) or not (Compressor). If you want to use the pointer, you need to init it with the = new Compressor(1, 1); line, if not, in the init location. If you are using a pointer, you access Set with a -> (and if you are not, a .) you should never have the mixed . and ->

Briyanna 06-03-2010 17:12

Re: Compressor Code problems
 
Quote:

class BuiltinDefaultCode : public IterativeRobot
{
// Declare variable for the robot drive system
RobotDrive *m_robotDrive; // robot will use PWM 1-4 for drive motors

// Declare a variable to use to access the driver station object
DriverStation *m_ds; // driver station object
UINT32 m_priorPacketNumber; // keep track of the most recent packet number from the DS
UINT8 m_dsPacketsReceivedInCurrentSecond; // keep track of the ds packets received in the current second

//Declare variable for the compressor
private: Compressor *compressor;

// Declare variables for the two joysticks being used
Joystick *m_rightStick; // joystick 1 (arcade stick or right tank stick)
Joystick *m_leftStick; // joystick 2 (tank left stick)

static const int NUM_JOYSTICK_BUTTONS = 16;
bool m_rightStickButtonState[(NUM_JOYSTICK_BUTTONS+1)];
bool m_leftStickButtonState[(NUM_JOYSTICK_BUTTONS+1)];


// Declare variables for each of the eight solenoid outputs
static const int NUM_SOLENOIDS = 6;
Solenoid *m_solenoids[(NUM_SOLENOIDS+1)];


enum { // drive mode selection
UNINITIALIZED_DRIVE = 0,
ARCADE_DRIVE = 1,
TANK_DRIVE = 2
} m_driveMode;

// Local variables to count the number of periodic loops performed
UINT32 m_autoPeriodicLoops;
UINT32 m_disabledPeriodicLoops;
UINT32 m_telePeriodicLoops;

public:
/**
* Constructor for this "BuiltinDefaultCode" Class.
*
* The constructor creates all of the objects used for the different inputs and outputs of
* the robot. Essentially, the constructor defines the input/output mapping for the robot,
* providing named objects for each of the robot interfaces.
*/
BuiltinDefaultCode(void) {
printf("BuiltinDefaultCode Constructor Started\n");

// Create a robot using standard right/left robot drive on PWMS 1, 2, 3, and #4
m_robotDrive = new RobotDrive(1, 3, 2, 4);

// Acquire the Driver Station object
m_ds = DriverStation::GetInstance();
m_priorPacketNumber = 0;
m_dsPacketsReceivedInCurrentSecond = 0;

// Define joysticks being used at USB port #1 and USB port #2 on the Drivers Station
m_rightStick = new Joystick(1);
m_leftStick = new Joystick(2);

// Iterate over all the buttons on each joystick, setting state to false for each
UINT8 buttonNum = 1; // start counting buttons at button 1
for (buttonNum = 1; buttonNum <= NUM_JOYSTICK_BUTTONS; buttonNum++) {
m_rightStickButtonState[buttonNum] = false;
m_leftStickButtonState[buttonNum] = false;
}


// Declare variable to Activate the Compressor
Compressor *compressor=new Compressor(1,1);
compressor ->Start();


// Iterate over all the solenoids on the robot, constructing each in turn
UINT8 solenoidNum = 1; // start counting solenoids at solenoid 1
for (solenoidNum = 1; solenoidNum <= NUM_SOLENOIDS; solenoidNum++)
{
m_solenoids[solenoidNum] = new Solenoid(solenoidNum);

}



// Set drive mode to uninitialized
m_driveMode = UNINITIALIZED_DRIVE;

// Initialize counters to record the number of loops completed in autonomous and teleop modes
m_autoPeriodicLoops = 0;
m_disabledPeriodicLoops = 0;
m_telePeriodicLoops = 0;

printf("BuiltinDefaultCode Constructor Completed\n");
}

//*Compressor

if (Joystick(1).GetRawButton(10)) //if button 10 is pressed on joystick 1 compressor will turn on
{
int compressor= new Compressor(1, 1);

compressor.Set(true);

}
if (Joystick(1).GetRawButton(11)) //if button 11 is pressed on joystick 1 compressor will turn off
{
compressor.Set(false);
}

// Solenoid

if (Joystick(1).GetRawButton(4)) //If button 4 is pressed on joystick 1 solenoid 1 will extrend
{
Solenoid(1).Set(true);
Solenoid(2).Set(false);
}
if (Joystick(2).GetRawButton(4)) //If button 4 is pressed on joystick 2 solenoid 1 will retract
{
Solenoid(1).Set(false);
Solenoid(2).Set(true);
}
if (Joystick(1).GetRawButton(5)) //If button 5 is pressed on joystick 1 solenoid 2 will extend
{
Solenoid(3).Set(true);
Solenoid(4).Set(false);
}
if (Joystick(2).GetRawButton(5)) //If button 5 is pressed on joystick 2 solenoid 2 will retract
{
Solenoid(3).Set(false);
Solenoid(4).Set(true);
}
if (Joystick(1).GetRawButton(2)) //If button 2 is pressed on joystick 1 solenoid 3(kicker) will extend
{
Solenoid(5).Set(true);
Solenoid(6).Set(false);
}
if (Joystick(2).GetRawButton(2)) //If button 2 is pressed on joystick 2 solenoid 3(kicker) will retrct
{
Solenoid(5).Set(false);
Solenoid(6).Set(true);
}

// Winch motor

Jaguar winchmotor(5); // Introduce Jaguar

if (Joystick(1).GetTrigger()) //If button is pressed
{
winchmotor.Set(0.5); //motor moves foward
}

if (Joystick(2).GetTrigger()) //If button is pressed
{
winchmotor.Set(-0.5

);

// motor moves backwards
}

This is most of the code and the reason there is a compressor code before the one that we are having trouble with is because we weren't sure weather or not to take it out of leave it. Also our spike stay an orange color when the robot is fully one and we would like to know what that means and what we can do about it.

byteit101 06-03-2010 17:30

Re: Compressor Code problems
 
you only need to change this bit of code:
Code:

//*Compressor

if (Joystick(1).GetRawButton(10)) //if button 10 is pressed on joystick 1 compressor will turn on
{
int compressor= new Compressor(1, 1); DELETE THIS LINE

compressor->Set(true);//Change this to a ->

}
if (Joystick(1).GetRawButton(11)) //if button 11 is pressed on joystick 1 compressor will turn off
{
compressor->Set(false);//Change this to a ->
}


mikets 06-03-2010 19:29

Re: Compressor Code problems
 
As far know, there is no "Set" method in the Compressor object even in the base classes it inherited from. In any case, if the compressor is wired correctly with a pressure switch, you shouldn't have to do much about the compressor object. Just instantiate it, start it and forget about it. When the compressor object is instantiated, a compressor task is started automatically, this task will check if the compressor has been enabled by Start(). If so, it will monitor the pressure switch and automatically turn the relay on and off if necessary to maintain the pressure. In other words, you can just do the following with the compressor object in the constructor of your robot and nothing else. Don't use a joystick button to turn the compressor on and off. It is automatic. You don't even have to destroy the compressor in the destructor because the robot code will never end anyway, but it would be a cleaner habit of coding.
Code:

class BuiltinDefaultCode : public IterativeRobot
{
private:
    Compressor *m_compressor;

...

public:
    BuiltinDefaultCode()
    {
        ...
        m_compressor = new Compressor(1, 1);
        m_compressor->Start();
        ...
    }
    ~BuiltinDefaultCode()
    {
        ....
        m_compressor->Stop();
        delete m_compressor;
        ....
    }
}



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

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