View Single Post
  #9   Spotlight this post!  
Unread 05-02-2004, 01:04
rdsideresistanc's Avatar
rdsideresistanc rdsideresistanc is offline
Registered User
AKA: Joel F
#0825 (SWVGS Maximus)
Team Role: Programmer
 
Join Date: Feb 2004
Location: nowhere
Posts: 11
rdsideresistanc is an unknown quantity at this point
Re: A few questions on programming the Control System

Quote:
Originally Posted by Avarik
Sorry, I realize my post wasn't too clear, so here is exactly what I want to do.

I simply need a way to control the solenoid with one button. In the code, you control a relay's forward/backward signal with 2 buttons (one for each). I was wondering how I could make it so 1 button could control a solenoid, where some state would change each time I hit it, sending a different signal.

Example: If I were to hit the trigger of the controller in port 1 the first time, it would cause a cylinder to open by sending the command to the solenoid. However, the next time hit this trigger, the cylinder would close. I am not sure it matters, but we will be using only double solenoids.

I want to create some sort of function which could do this, as I would need to set up quite a few for this years robot. I have been looking through the code, trying to find a way to do this succesfully for a while now, and I can't seem to do it.

My main problem is that I can't find a way to detect whether or not a trigger has been hit. I tried #if p1_sw_trig, but I got a malformed function error. If I try #if (p1_sw_trig) then it says expected ')' and malformed function...
I have implemented this very thing into our FRC code. Basically you need one button to just flip the spike from green to red (or vice versa).

Code:
void toggle_spike(unsigned char button, unsigned char relayfwd, unsigned char relayrev) {
  if (button == 1) {
    cyl_count++;
  } else {
    cyl_count = 0;
  }
  if (cyl_count == 1) {
    if (relayfwd == 1) {
      relayfwd = 0;
      relayrev = 1;
    } else {
      relayfwd = 1;
      relayrev = 0;
    }
  } else {
    relayfwd = relayfwd;
    relayrev = relayrev;
  }
}
I think that should work. Just initialize cyl_count at the top of user_routines.c like:

Code:
unsigned int cyl_count = 0;
Then if you just place it where your current relay definitions are in user_routines.c and pass it the correct variables. Like:

instead of:
Code:
relay1_fwd = 1;
relay1_rev  = 1;
put this:
Code:
toggle_spike(p1_sw_trig,relay1_fwd,relay1_rev);
Keep in mind that im used to C-based languages...i've not done much programming in C....someone verify my code maybe?

Last edited by rdsideresistanc : 05-02-2004 at 02:52.