![]() |
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! |
Re: A few questions on programming the Control System
Quote:
Code:
bool pressed=false; //is switch pressed (put this somewhere where it will remain globally constant)Quote:
|
Re: A few questions on programming the Control System
Quote:
|
Re: A few questions on programming the Control System
Quote:
|
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! |
Re: A few questions on programming the Control System
Quote:
Quote:
|
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 |
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... |
Re: A few questions on programming the Control System
Quote:
Code:
void toggle_spike(unsigned char button, unsigned char relayfwd, unsigned char relayrev) {Code:
unsigned int cyl_count = 0;instead of: Code:
relay1_fwd = 1;Code:
toggle_spike(p1_sw_trig,relay1_fwd,relay1_rev); |
Re: A few questions on programming the Control System
Interesting, and thanks! I'll test this tomorrow if I can.
|
Re: A few questions on programming the Control System
Quote:
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. |
Re: A few questions on programming the Control System
Quote:
Code:
typedef unsigned char bool;Code:
typedef enum{ |
Re: A few questions on programming the Control System
Quote:
|
Re: A few questions on programming the Control System
Quote:
|
Re: A few questions on programming the Control System
Quote:
|
Re: A few questions on programming the Control System
Quote:
|
Re: A few questions on programming the Control System
Quote:
|
Re: A few questions on programming the Control System
Here is how I would implement the code (from which you should be able to figure out how to implement your code with pointers)
Code:
void toggle_single_solenoid(unsigned char button, unsigned char *prev_button, unsigned char *relay_fwd)Code:
toggle_single_solenoid(p1_sw_trig, &prev_p1_sw_trig, &relay1_fwd); |
Re: A few questions on programming the Control System
I haven't tried it, but can you have a pointer to a bit field? relay1_fwd is a macro with the value LATDbits.LATD0. Just curious.
|
Re: A few questions on programming the Control System
What exactly is prev_button?
And thanks...I've been at this for too long... Shouldn't take me this long! |
Re: A few questions on programming the Control System
Alright, I finally figured it out! Here is how I did it.
Code:
if (p1_sw_trig && rel1==0)rel1 and rel2 are simply declared as ints, where rel1 is initialized to 0, and rel2 to 1. This makes it go forward at first, then backwards the next time. |
Re: A few questions on programming the Control System
Quote:
|
| All times are GMT -5. The time now is 02:16. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi