Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Spike Relay (http://www.chiefdelphi.com/forums/showthread.php?t=113562)

MoMo 15-02-2013 13:47

Spike Relay
 
Code:

#include "WPILib.h"

// Team 1721 mecanum code 2013 By: Zakary Tobine at 2/14/13 10:10

// Needs to add 2 relays; one for motor for shooter; one for frishbee pusher

const char inputShape[255] = {0,1,3,4,5,6,7,9,10,11,12,13,15,16,17,18,19,21,22,23,24,25,27,28,29,30,31,
                33,34,35,36,37,38,40,41,42,43,44,46,47,48,49,50,52,53,54,55,56,58,59,60,61,62,
                64,65,66,67,68,70,71,72,73,74,76,77,78,79,80,82,83,84,85,86,88,89,90,91,92,94,
                95,96,97,98,100,101,102,103,104,106,107,108,109,110,112,113,114,115,116,117,
                118,119,120,121,121,122,123,123,124,124,125,125,125,126,126,126,126,126,127,
                127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
                128,128,128,128,128,129,129,129,130,130,131,131,132,133,133,134,135,136,
                137,138,139,140,141,142,144,145,146,147,148,150,151,152,153,154,156,157,158,
                159,160,162,163,164,165,166,168,169,170,171,172,174,175,176,177,178,180,181,
                182,183,184,186,187,188,189,190,192,193,194,195,196,198,199,200,201,202,204,
                205,206,207,208,210,211,212,213,214,216,217,218,219,220,221,223,224,225,226,
                227,229,230,231,232,233,235,236,237,238,239,241,242,243,244,245,247,248,249,
                250,251,253,254,255};

float InputShape(float userValue)
        {
                int iUserValue;

                iUserValue = (int)(userValue * 127);
                iUserValue += 127;
                iUserValue = inputShape[iUserValue];
                userValue = iUserValue - 127;
                userValue /= 127;
                return userValue;
        }

class RobotDemo : public SimpleRobot
{
        RobotDrive myRobot; // robot drive system
        Joystick stick; // only joystick
        Relay relay1; // Relay 1 for shooter
        Relay relay2; // Realy 2 for Pusher
               
public:
        RobotDemo(void):
                myRobot(1, 2, 3, 4),        // these must be initialized in the same order
                stick(1)                // as they are declared above.
       
       
       
        {
       
                stick.SetAxisChannel(Joystick::kTwistAxis, 3);// Add the 3rd axis
                myRobot.SetExpiration(0.1);// The time the motors stop moving after a value is sent 
                Relay relay1(1,Relay::kForwardOnly);
                Relay relay2(2,Relay::kForwardOnly);
        }

       
        void Autonomous(void)
        {
                // Commented out till a later date
               
                //myRobot.SetSafetyEnabled(false);
                //myRobot.Drive(-0.5, 0.0);        // drive forwards half speed
                //Wait(2.0);                                //    for 2 seconds
                //myRobot.Drive(0.0, 0.0);        // stop robot
        }

        /**
        * Runs the motors with one joystick mecanum.
        */
        void OperatorControl(void)
        {
                myRobot.SetSafetyEnabled(true);
                while (IsOperatorControl())
                {
               
                        float x = InputShape(stick.GetX());
                        float y = InputShape(stick.GetY());
                        float z = InputShape(-1*stick.GetTwist());
               
                        myRobot.MecanumDrive_Cartesian(x, y, z);// Mecanum drive single joystick drive
                       
                        if (stick.GetRawButton(1)) // Spike relay for Shooter wheel
                            relay1.Set(Relay::kOn);
                        else
                            relay1.Set(Relay::kOff);
                       
               
                        if (stick.GetRawButton(2)) // Spike relay for pusher
                                relay1.Set(Relay::kOn);
                        else
                            relay2.Set(Relay::kOff);
               
               
                        Wait(0.005);                                // wait for a motor update time
                }
        }
       
        /**
        * Runs during test mode
        */
        void Test() {

        }
};

START_ROBOT_CLASS(RobotDemo);



this is our code so far but when i try to build it it says

Code:

Build Started in Project 'SimpleTemplate':  2013-02-15 13:40:32
Generation of makefiles started.
Generation of makefiles finished (Elapsed Time: 00:00).
Platform: Wind River VxWorks 6.3
Command: make --no-print-directory BUILD_SPEC=PPC603gnu DEBUG_MODE=1 TRACE=1
Working Directory: C:/WindRiver/wrwb-debugmode-workspace/SimpleTemplate/PPC603gnu
if [ ! -d "`dirname "SimpleTemplate_partialImage/Debug/Objects/SimpleTemplate/MyRobot.o"`" ]; then mkdir -p "`dirname "SimpleTemplate_partialImage/Debug/Objects/SimpleTemplate/MyRobot.o"`"; fi;echo "building SimpleTemplate_partialImage/Debug/Objects/SimpleTemplate/MyRobot.o"; ccppc -g -mcpu=603 -mstrict-align -mno-implicit-fp -mlongcall -ansi -Wall  -MD -MP -mlongcall  -IC:/WindRiver/vxworks-6.3/target/h -IC:/WindRiver/vxworks-6.3/target/h/WPILib -IC:/WindRiver/vxworks-6.3/target/h/wrn/coreip  -DCPU=PPC603 -DTOOL_FAMILY=gnu -DTOOL=gnu -D_WRS_KERNEL    -o "SimpleTemplate_partialImage/Debug/Objects/SimpleTemplate/MyRobot.o" -c "C:/WindRiver/wrwb-debugmode-workspace/SimpleTemplate/MyRobot.cpp"
building SimpleTemplate_partialImage/Debug/Objects/SimpleTemplate/MyRobot.o
C:/WindRiver/wrwb-debugmode-workspace/SimpleTemplate/MyRobot.cpp: In constructor `RobotDemo::RobotDemo()':
C:/WindRiver/wrwb-debugmode-workspace/SimpleTemplate/MyRobot.cpp:47: error: no matching function for call to `Relay::Relay()'
C:/WindRiver/vxworks-6.3/target/h/WPILib/Relay.h:26: note: candidates are: Relay::Relay(const Relay&)
C:/WindRiver/vxworks-6.3/target/h/WPILib/Relay.h:32: note:                Relay::Relay(UINT8, UINT32, Relay::Direction)
C:/WindRiver/vxworks-6.3/target/h/WPILib/Relay.h:31: note:                Relay::Relay(UINT32, Relay::Direction)
C:/WindRiver/wrwb-debugmode-workspace/SimpleTemplate/MyRobot.cpp:47: error: no matching function for call to `Relay::Relay()'
C:/WindRiver/vxworks-6.3/target/h/WPILib/Relay.h:26: note: candidates are: Relay::Relay(const Relay&)
C:/WindRiver/vxworks-6.3/target/h/WPILib/Relay.h:32: note:                Relay::Relay(UINT8, UINT32, Relay::Direction)
C:/WindRiver/vxworks-6.3/target/h/WPILib/Relay.h:31: note:                Relay::Relay(UINT32, Relay::Direction)
C:\WindRiver\vxworks-6.3\host\x86-win32\bin\make.exe: *** [SimpleTemplate_partialImage/Debug/Objects/SimpleTemplate/MyRobot.o] Error 1
Build Failed in Project 'SimpleTemplate' (Process Exit Value was 2):  2013-02-15 13:40:44  (Elapsed Time: 00:12)


i know im forgetting something i just dont know what lol, any help? thanks

bob.wolff68 17-02-2013 00:43

Re: Spike Relay
 
The problem is one of initialization and instantiation. It's unfortunate that C++ is so darned heavily laden with nomenclature and syntax, but alas it is... Please see a snip of your code with my added '// Initialize here' and '// don't initialize here comment

Code:

public:
        RobotDemo(void):
                myRobot(1, 2, 3, 4),        // these must be initialized in the same order
                stick(1)                // as they are declared above.
// Initialize here       
        {
       
                stick.SetAxisChannel(Joystick::kTwistAxis, 3);// Add the 3rd axis
                myRobot.SetExpiration(0.1);// The time the motors stop moving after a value is sent 
// Don't initialize here
                Relay relay1(1,Relay::kForwardOnly);
                Relay relay2(2,Relay::kForwardOnly);
        }

As an example, you'll see, the template declares 'stick' above the snip that I have pasted above, but it INITIALIZES it just above my comment as 'stick(1)'. This is similar to what you want to do. You have properly declared relay1 and relay2 up top, but you didn't initialize them. See the changes below marked with // CHANGE

Code:

public:
        RobotDemo(void):
                myRobot(1, 2, 3, 4),        // these must be initialized in the same order
                stick(1),                // as they are declared above.
// CHANGE - added                       
                relay1(1,Relay::kForwardOnly),
                relay2(2,Relay::kForwardOnly)
        {
       
                stick.SetAxisChannel(Joystick::kTwistAxis, 3);// Add the 3rd axis
                myRobot.SetExpiration(0.1);// The time the motors stop moving after a value is sent 
// CHANGE - removed from here
        }



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

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