Go to Post Valentine's day, who has time for Valentine's day?????? I have code to write!! - paulcd2000 [more]
Home
Go Back   Chief Delphi > Technical > Control System
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 03-02-2004, 07:21
Avarik Avarik is offline
Registered User
#0022
 
Join Date: Jan 2004
Location: Chatsworth, CA
Posts: 75
Avarik is an unknown quantity at this point
A few questions on programming the Control System

First off, let me start by saying I really don't know C too well. I am having a hard time programming, but I am attempting to do it anyway. Now...I have a few questions for programming the control system.

Firstly, how would I set up a system to push 1 button to open and close pneumatics? I was thinking about having a state which is altered if the button is pushed, but I cannot figrure out how to do this (from decleration to initialization to writing the code!)

Secondly, how do I create a program which will overide all other code and execute a set of commands? This would be to use pneumatics to shift gears in a gearbox. I am unsure how to program the code, and set up overiding the system. I was thinking about using interupts, but I don't know how to call them (I have Kevin's code with the interupts added in.)

Thanks in advance! Any help is appreciated!
  #2   Spotlight this post!  
Unread 03-02-2004, 08:48
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
Re: A few questions on programming the Control System

Quote:
Originally Posted by Avarik
Firstly, how would I set up a system to push 1 button to open and close pneumatics? I was thinking about having a state which is altered if the button is pushed, but I cannot figrure out how to do this (from decleration to initialization to writing the code!)
There could be another (better) way but the way I did it last year (now in C) would be as follows:
Code:
bool pressed=false; //is switch pressed (put this somewhere where it will remain globally constant)
if(p1_sw_top&&!pressed)
{
    pressed=true;//set the toggle value
    relay1_fwd=(!relay1_fwd);//set the relay state
}
else if(p1_sw_top)
{
    //do something else if you want (but you don't have to)
}
else
{
    pressed=false;//turn off the toggle
}
Quote:
Originally Posted by Avarik
Secondly, how do I create a program which will overide all other code and execute a set of commands? This would be to use pneumatics to shift gears in a gearbox. I am unsure how to program the code, and set up overiding the system. I was thinking about using interupts, but I don't know how to call them (I have Kevin's code with the interupts added in.)
I'm not exactly sure what you need but you can use an if statement to check for a certain state and call functions you create (run_drive_code() and run_override_code() for example) based on the state. That would probably be the easiest method unless you need multiple override options in which case a switch statement would probably be useful.
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #3   Spotlight this post!  
Unread 03-02-2004, 09:04
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: A few questions on programming the Control System

Quote:
Originally Posted by Adam Shapiro
Code:
bool pressed=false;
Do we actually have a built in boolean type? This is C and C typically doesn't have a built in bool. Just wondering.
__________________

  #4   Spotlight this post!  
Unread 03-02-2004, 21:31
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
Re: A few questions on programming the Control System

Quote:
Originally Posted by Texan
Do we actually have a built in boolean type? This is C and C typically doesn't have a built in bool. Just wondering.
I guess you are right. I'm more used to C++ so sometimes I forget the simple differences.
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #5   Spotlight this post!  
Unread 04-02-2004, 03:01
Avarik Avarik is offline
Registered User
#0022
 
Join Date: Jan 2004
Location: Chatsworth, CA
Posts: 75
Avarik is an unknown quantity at this point
Re: A few questions on programming the Control System

I tried the code and it didn't work, thanks for the help though! I have a much better understanding of it. However, it seems I cannot type in p1_sw_top as a variable for an if statement, doesn't seem to work.

Also, I need to do this multiple times...I was wondering if there would be a way to set up a function and call it multiple times sending different values in for different solenoids?

Once again, thank you very much for the help!
  #6   Spotlight this post!  
Unread 04-02-2004, 16:22
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: A few questions on programming the Control System

Quote:
Originally Posted by Adam Shapiro
I guess you are right. I'm more used to C++ so sometimes I forget the simple differences.
Yeah, I'm a C++ guy too!

Quote:
Also, I need to do this multiple times...I was wondering if there would be a way to set up a function and call it multiple times sending different values in for different solenoids?
Do you really mean a solenoid? They are just on or off systems. Give a few more details on what you want the function to do and I can probably help. (Probably... )
__________________


Last edited by Ryan M. : 04-02-2004 at 16:29.
  #7   Spotlight this post!  
Unread 04-02-2004, 19:29
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: A few questions on programming the Control System

You can still sort of use bools.

typedef bool unsigned char;

or

typedef unsigned char bool;

I can never remember which (more of a C++ guy myself too). I think it's the top one though.

Also:

#define TRUE 1
#define FALSE 0
  #8   Spotlight this post!  
Unread 05-02-2004, 00:29
Avarik Avarik is offline
Registered User
#0022
 
Join Date: Jan 2004
Location: Chatsworth, CA
Posts: 75
Avarik is an unknown quantity at this point
Re: A few questions on programming the Control System

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...
  #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.
  #10   Spotlight this post!  
Unread 05-02-2004, 01:56
Avarik Avarik is offline
Registered User
#0022
 
Join Date: Jan 2004
Location: Chatsworth, CA
Posts: 75
Avarik is an unknown quantity at this point
Re: A few questions on programming the Control System

Interesting, and thanks! I'll test this tomorrow if I can.
  #11   Spotlight this post!  
Unread 05-02-2004, 07:31
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,560
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: A few questions on programming the Control System

Quote:
Originally Posted by rdsideresistanc
Keep in mind that im used to C-based languages...i've not done much programming in C....someone verify my code maybe?
you need to pass relayfwd and relayrev as pointers so that the modifications you make don't get "thrown out" when you exit the function.

I'm also not sure what the purpose of cyl_count is. Since you increment it each time the button is pressed, and reset each time it isn't pressed, it will only hold the value of 0 or 1. You could make the code much simpler by changing if (cyl_count == 1) to if (button) and removing the code before that.

Based on the sound of the variable name (cylinder count?), it seems that you may want to keep track of how many times you activated a cylinder. If you want to do that, remove the else {cyl_count = 0} part and change the if statement like I said above.

However, you only then would have the count of how many times total cylinders had been activated. You could pass cyl_count as a pointer again and have multiple variables for multiple cylinders.
  #12   Spotlight this post!  
Unread 05-02-2004, 08:02
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: A few questions on programming the Control System

Quote:
Originally Posted by Jay Lundy
You can still sort of use bools.

typedef bool unsigned char;

or

typedef unsigned char bool;

I can never remember which (more of a C++ guy myself too). I think it's the top one though.

Also:

#define TRUE 1
#define FALSE 0
It'd be
Code:
typedef unsigned char bool;
Also, here's a another way (taken from HartRobots.com):
Code:
typedef enum{
true = 1, false = 0
} bool;
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #13   Spotlight this post!  
Unread 05-02-2004, 11:13
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: A few questions on programming the Control System

Quote:
Originally Posted by Raven_Writer
Code:
typedef enum{
true = 1, false = 0
} bool;
According to one of my programming mentors, enums don't work with this compiler. I didn't actually try it myself, but I trust him enough to think he did it right. It was also on the edubot, preseason. But, the compilers the same, so if it didn't work on one, it probably won't work on the other.
__________________

  #14   Spotlight this post!  
Unread 05-02-2004, 11:17
Mike Soukup's Avatar
Mike Soukup Mike Soukup is offline
Software guy
FRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Schaumburg, IL
Posts: 797
Mike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond repute
Re: A few questions on programming the Control System

Quote:
Originally Posted by Texan
According to one of my programming mentors, enums don't work with this compiler. I didn't actually try it myself, but I trust him enough to think he did it right. It was also on the edubot, preseason. But, the compilers the same, so if it didn't work on one, it probably won't work on the other.
If they don't work, we're all in trouble since there's an enum in 'ifi_utilities.h'. Our current code has multiple enum's and we haven't had any problems with them.
  #15   Spotlight this post!  
Unread 05-02-2004, 11:26
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: A few questions on programming the Control System

Quote:
Originally Posted by Mike Soukup
If they don't work, we're all in trouble since there's an enum in 'ifi_utilities.h'. Our current code has multiple enum's and we haven't had any problems with them.
OK, well, I'll guess I have to yell at Greg. He probably did it wrong. He actually is a Java programmer, not C/C++. Thanks for telling me.
__________________

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
What do you wish you knew about the new control system? Joe Ross Control System 2 09-01-2004 21:47
Need a FIRST Robotics control system kershawrobotics General Forum 3 07-07-2003 09:49
control system worth more than $500 archiver 2001 8 24-06-2002 02:00
control system programming archiver 2000 17 23-06-2002 22:14
Ok, how much is the control system worth? archiver 2001 6 23-06-2002 22:05


All times are GMT -5. The time now is 02: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