Go to Post Or you could go to the Waterloo or Greater Toronto regional, walk up to anyone in their pit, and ask. You may end up feeling like you asked for a sip of water and ended up soaked by a fire hose, but you won't walk away disappointed. - Richard Wallace [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-01-2009, 13:02
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Exclamation Please help Program Relays in WindRiver....

Hello there, i need some help trying to program relays using windriver. Let's just say i want to program a relay plugged into relay 1. When its forward, the motor turns one way, when its reversed the motor goes the other way. I want this to be triggered by a joystick buttons. Forward is button 3 and reverse is button 4. This will be for the "leftStick" Here is the code i have, can anyone help? Please, im somewhat confused on how to program relays.
Attached Files
File Type: cpp BuiltinDefaultCode.cpp (3.8 KB, 70 views)
__________________
"I would love to change the world but no one will give me the source code"
  #2   Spotlight this post!  
Unread 27-01-2009, 13:29
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: Please help Program Relays in WindRiver....

Are you sure you attached the proper file? I don't see anything in there mentioning the joystick buttons or relay control.

Anyway, you have not described your goal completely. Do you want the motor to run only while a button is pressed? What do you want to happen when both buttons are pressed? Do you want the button to choose the direction and start the motor, but have the motor to continue to run after you release the button, and if so, do you ever want to be able to stop the motor and how do you want to do it? What do you want the motor to be doing when the robot is enabled at the beginning of the match?

The answers to these questions will influence the appropriate program structure for implementing what you want. It will probably be as simple as a pair of if statements, or an if/elseif/else.
  #3   Spotlight this post!  
Unread 27-01-2009, 13:40
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Exclamation Re: Please help Program Relays in WindRiver....

ok, let's just say, if you push button 2, that will turn the motor on relay 1 on forward direction. when they push it again, it will turn it off.


also let's say button 3 is pushed, when they hold it down, it moves the motor relay 2 in the forward direction. otherwise, it doesnt move at all.


How would i do these two things? Please help, thank you.

Also, that fiel i attached is the current file i have for what ive worked on so far. please feel free to add to it or just post what i can add to make the two thing above work. Thank You again. I know for a button its
if (leftStick->GetRawButton(1)) { , but thats all i know.
__________________
"I would love to change the world but no one will give me the source code"
  #4   Spotlight this post!  
Unread 27-01-2009, 16:02
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: Please help Program Relays in WindRiver....

Quote:
ok, let's just say, if you push button 2, that will turn the motor on relay 1 on forward direction. when they push it again, it will turn it off.
This is a "push-on, push-off" or "toggle" function. Our team uses LabVIEW, so I can't be certain I'm giving you working code, but the structure should be correct.

Code:
// Define and initialize a couple of variables
    static char current_state = 0; // what the button was last time we looked
    static char motor1state = 0; // what the last thing we told the motor to do was
    :
    :
    // Read the button
    current_state = leftStick->GetRawButton(2);
    // Did the button just get pushed?
    if (current_state != previous_state) {
      // Yes, the button wasn't pushed before, but it is now
      if (current_state == 1) {
        // Is the motor already on?
        if (motor1state == 0} {
          // Yes, the motor is on. Turn it off.
          motor1state = 1;
          motor1Relay->Set(Relay::kForward);
        } else {
          // No, the motor is off.  Turn it on.
          motor1state = 0;
          motor1Relay->Set(Relay::kOff);
        }
    }
    // remember the button so you don't do this more than once each press
    previous_state = current_state;
You can get fancy with using the kForward and kOff enumerations in the motor state variable if you like, so the code becomes a little more self-documenting, but that's not important right now.

Quote:
also let's say button 3 is pushed, when they hold it down, it moves the motor relay 2 in the forward direction. otherwise, it doesnt move at all.
This is easy, as it requires no "memory" of past events.

Code:
    if (left_stick->GetRawButton(3) == 1) {
      motor2Relay->Set(Relay::kForward);
    } else {
      motor2Relay->Set(Relay::kOff);
    }
I have used more braces than necessary, and my formatting convention might not match what you want to use. This should give you a good start on what you need to do, though.
  #5   Spotlight this post!  
Unread 28-01-2009, 08:56
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Re: Please help Program Relays in WindRiver....

hello, i seem to get a bunch of error messages about expected ; or { or } after or before the ifs and else's..... for the toggle on and off code.... any suggestions?
__________________
"I would love to change the world but no one will give me the source code"

Last edited by programmr : 28-01-2009 at 10:29.
  #6   Spotlight this post!  
Unread 28-01-2009, 11:16
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: Please help Program Relays in WindRiver....

I have three suggestions. First, notice that I forgot to declare the previous_state variable in my example. (it should be just like the current_state one).

Second, notice that I accidentally used a close brace } instead of a close parenthesis ) character after the test expression on the third if.

Third, just use what I posted as an example of how to do it, not as a complete copy-and-paste solution to your specific problem. Read it, understand it, and then write your own code.

Last edited by Alan Anderson : 28-01-2009 at 11:20.
  #7   Spotlight this post!  
Unread 28-01-2009, 11:42
programmr's Avatar
programmr programmr is offline
Registered User
AKA: Face
FRC #0522
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Staten Island, NY
Posts: 83
programmr is a jewel in the roughprogrammr is a jewel in the roughprogrammr is a jewel in the rough
Send a message via AIM to programmr
Re: Please help Program Relays in WindRiver....

ok thank you very much... good luck this season
__________________
"I would love to change the world but no one will give me the source code"
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Labview Dashboard and Windriver Example Help sircedric4 Programming 7 25-02-2009 01:58
Need help in c++ and windriver jkjohnson C/C++ 3 13-01-2009 18:50
help:Downloading the project in windriver mahmosh C/C++ 5 10-01-2009 10:08
Problem Downloading Program from WindRiver to Driver Station The_Laughing_ManMII C/C++ 10 09-01-2009 20:03
pic: please help us please mortals CD47-Bot Robot Showcase 5 25-01-2004 11:03


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

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