Go to Post No matter what you do and how well you try to protect them, some people are just out there to be candidates for the Darwin Awards! - Jay H 237 [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 14-07-2009, 17:34
Happyisgood Happyisgood is offline
Registered User
FRC #3161 (Tronic Titans)
Team Role: College Student
 
Join Date: May 2009
Rookie Year: 2009
Location: Canada
Posts: 23
Happyisgood is an unknown quantity at this point
C++ Relay Code?

Hey!

I seem to have a constant stream of programming problems, but here's my problem.

I can get a relay to work in a basic code (two drive motors, left and right, one joystick plus a single relay.) However whenever I try to move the code over to my FULL bot code (with many motors and two Joysticks) the code just fails.

What I'm using is the following (only parts of it)

Code:
#include <WPILib.h>

class RobotDemo public IterativeRobot
{
Relay *hRelay;
Joystick *stickDrive;

public:
RobotDemo()
{
     hRelay = new Relay(1);
     stickDrive = new Joystick(1);
}
void TeleopPeriodic()
{
     if(stickDrive->GetTrigger())
            hRelay->Set(Relay::kForward);
     else
            hRelay->Set(Relay::kOff);
}
};
START_ROBOT_CLASS(RobotDemo);
This is the parts of the code that included any Relay related stuff. If that runs alone (or almost alone) it works, if that runs in the full program, it doesn't. Any suggestions?


EDIT : Perhaps I should rephrase. What could possibly be in my code to cause this particular part of the code not to work?
__________________
2009 - Waterloo Regional - Regional Finalist
2009 - Waterloo Regional - Engineering Inspiration Award


________________________

2009 Team Member 1334

Last edited by Happyisgood : 14-07-2009 at 21:01.
Reply With Quote
  #2   Spotlight this post!  
Unread 14-07-2009, 17:52
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: C++ Relay Code?

Your logic seems good, but here's a question....Are you trying to have the relay fire in teleop or autonomous?

If you're trying to do teleop, your logic needs to be in the TeleopPeriodic function.

If you're trying to do autonomous, you have to keep in mind that the inputs are zero'd out during autonomous and plan your logic around that. As is, the button will always be false and therefore the relay will always be in the off state.
Reply With Quote
  #3   Spotlight this post!  
Unread 14-07-2009, 20:49
Happyisgood Happyisgood is offline
Registered User
FRC #3161 (Tronic Titans)
Team Role: College Student
 
Join Date: May 2009
Rookie Year: 2009
Location: Canada
Posts: 23
Happyisgood is an unknown quantity at this point
Re: C++ Relay Code?

My bad, I wrote the wrong function down when copying it to the program. That was NOT the problem.
__________________
2009 - Waterloo Regional - Regional Finalist
2009 - Waterloo Regional - Engineering Inspiration Award


________________________

2009 Team Member 1334
Reply With Quote
  #4   Spotlight this post!  
Unread 14-07-2009, 21:37
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: C++ Relay Code?

Did you make sure that there isn't something else instantiated as Relay(1)? If there's something somewhere else overwriting your value you could never see your output.

I would suggest adding printfs to make sure that the code is being reached like you think it is.

This type of problem is usually something silly that is overlooked, most likely in the place that you least expect.

You said that it worked in a smaller test bed. I'm assuming it was with the same physical hardware setup. It's worth checking
Reply With Quote
  #5   Spotlight this post!  
Unread 14-07-2009, 22:11
Happyisgood Happyisgood is offline
Registered User
FRC #3161 (Tronic Titans)
Team Role: College Student
 
Join Date: May 2009
Rookie Year: 2009
Location: Canada
Posts: 23
Happyisgood is an unknown quantity at this point
Re: C++ Relay Code?

Nope, there is no other Relay present, I manually cleared out every reference to relays in the code then manually re-entered them. I'm going to scan over the code a few more times tonight, if I find anything I'll let you know, I may make changes and test them tomorrow morning.
__________________
2009 - Waterloo Regional - Regional Finalist
2009 - Waterloo Regional - Engineering Inspiration Award


________________________

2009 Team Member 1334
Reply With Quote
  #6   Spotlight this post!  
Unread 15-07-2009, 07:55
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: C++ Relay Code?

I will echo what Dave said: Put in printf's to make sure that your code goes where you think it should. This would reveal if you were using the wrong joystick port, for example.
Reply With Quote
  #7   Spotlight this post!  
Unread 15-07-2009, 22:10
Happyisgood Happyisgood is offline
Registered User
FRC #3161 (Tronic Titans)
Team Role: College Student
 
Join Date: May 2009
Rookie Year: 2009
Location: Canada
Posts: 23
Happyisgood is an unknown quantity at this point
Re: C++ Relay Code?

Ok, I will have another 5 hours or so with the Robot tomorrow, so I'll try getting it up and running then. I actually have a feeling that its a problem with my relay declaration, the reason I'm thinking this is because when I move the line

hRelay->Set(Relay::kForward);

to the TeleopPeriodic() function (essentially eliminating the need to press the trigger) the relay still remains inactive (however it is initialized I believe, the light is not flashing but solid orangeyred.)

What could cause this? Is there a limit on the number of variables etc. that can be declared in the robot? Anyway, once I'm back with the robot tomorrow I'll comment out mostly all of the code until it gets working, then slowly re-intigrate aspects of the code until it stops working and troubleshoot from there. If the schools internet is up I'll keep this updated, if its not I'll post an update tomorrow night. I need this working by Friday night so I really hope this can be resolved quickly
__________________
2009 - Waterloo Regional - Regional Finalist
2009 - Waterloo Regional - Engineering Inspiration Award


________________________

2009 Team Member 1334
Reply With Quote
  #8   Spotlight this post!  
Unread 15-07-2009, 22:23
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: C++ Relay Code?

FYI relays are solid orange whether or not they have a signal so that's not really a good indication. It just means you're getting power.

Your approach seems like a good plan about backing things out and reintegrating. Maybe before you do that, throw some prints into the periodic function to make sure it's being called properly. If it isn't then you may be chasing a ghost.
Reply With Quote
  #9   Spotlight this post!  
Unread 16-07-2009, 08:27
Happyisgood Happyisgood is offline
Registered User
FRC #3161 (Tronic Titans)
Team Role: College Student
 
Join Date: May 2009
Rookie Year: 2009
Location: Canada
Posts: 23
Happyisgood is an unknown quantity at this point
Re: C++ Relay Code?

Yeah, I realize that, I'll try to figure out how to use printf's in robot code. I never have before because usually my code works (or comes very close to working) and I've never had a need.
__________________
2009 - Waterloo Regional - Regional Finalist
2009 - Waterloo Regional - Engineering Inspiration Award


________________________

2009 Team Member 1334
Reply With Quote
  #10   Spotlight this post!  
Unread 16-07-2009, 13:12
Happyisgood Happyisgood is offline
Registered User
FRC #3161 (Tronic Titans)
Team Role: College Student
 
Join Date: May 2009
Rookie Year: 2009
Location: Canada
Posts: 23
Happyisgood is an unknown quantity at this point
Re: C++ Relay Code?

Problem solved.

After about an hour of work I got desperate and started looking in the most obscure places. I then realized what was wrong. We have two projects on the laptop, both nearly identical, they both actually do the exact same thing for the robot. The only difference is that one is uploaded and the other is not. I was editing/building the one that IS NOT uploading, and was constantly re-loading the one that was never changed. My initial code (see post 1) worked when put into the RIGHT project.

Time to have some fun and add in a custom dashboard!

Thanks everyone for the help!
Nick
__________________
2009 - Waterloo Regional - Regional Finalist
2009 - Waterloo Regional - Engineering Inspiration Award


________________________

2009 Team Member 1334
Reply With Quote
  #11   Spotlight this post!  
Unread 16-07-2009, 14:54
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: C++ Relay Code?

Glad to hear that it worked. Your comments about the dashboard reminded me that I wanted to publish our dashboard framework. It sat on top of the WPILib interface and made things really easy to interface with. I need to clean it up a bit to make it less intimidating to read (we had over 100 pieces of data that we were sending to the dashboard). Look for something in the next day or so.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Relay (Spike) elbuo Electrical 2 09-02-2009 20:36
Relay Problems starsROBOTICS NI LabVIEW 2 30-01-2009 23:40
Instance relay Team_486 Programming 0 28-03-2007 09:56
Intermittent CODE ERROR, followed by uncommanded relay switching tcj103 Programming 4 22-01-2007 02:59
Relay outputs on rc jdawson Electrical 4 26-01-2003 12:51


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

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