|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Rookie programmer in need of help.
Hello all,
This is pretty much my first year of doing programming in C for purposes other than using it in robots. I was wondering on how to put a line of code in to add a button that would act as a click switch and tell the RC that a button was hit, and then it would proceed onto the next line of programming. Thanks. |
|
#2
|
||||
|
||||
|
Re: Rookie programmer in need of help.
Quote:
Do you want the button to be at the operator interface (such as a momentary switch that the driver pushes) or on the robot (such as a micro switch indicating an arm is at the end of its travel)? |
|
#3
|
|||
|
|||
|
Re: Rookie programmer in need of help.
Well, I wanted the button to be placed in front of the robot, then as the driver pushes the robot forward, if the button is pressed (vision tetra is being pushed against the robot), then the program would then execute it's next stage.
|
|
#4
|
||||
|
||||
|
Re: Rookie programmer in need of help.
Quote:
You would need to connect your switch to digital input #1 on the robot controller for this to work. Does this help? |
|
#5
|
|||||
|
|||||
|
Re: Rookie programmer in need of help.
I think you are saying that after the switch is hit, then a new section of code is enabled. Yes? And I think you want the code to remember that the switch had been hit, even after the switch is no longer pressed?
(experienced programmers, please check for errors. I did this off the top of my head!) In the file user_routines.c... In the function User_Initialization(), make sure: Code:
// tell the controller that we want to use io pin 15 as an input: // digital_io_15 = INPUT; // or whichever input you want to use also, somewhere in user_routines.c, near the top: Code:
#define MY_SWITCH rc_dig_in15 // makes the other code easier to read near the top Code:
static unsigned char switchWasHit = 0; Code:
// when the switch is hit, it closes, and pulls the input low i.e. 0
//
if ( MY_SWITCH == 0 )
switchWasHit = 1; // remember forever
if ( switchWasHit )
{
/* this is never executed before the switch is hit, and is
always executed after the switch is hit
*/
}
Does that help? |
|
#6
|
||||
|
||||
|
Re: Rookie programmer in need of help.
I think he may want to go even further and basically have a debug switch. When he hits it, then the next line of code is executed, then the robot waits again.
I'm not sure if this is possible on the RC. On a computer, debuggers typically work by hooking into a software interrupt (don't remember which one right now) and stopping execution when it is activated. I'm not sure if a similar thing exists on the RC, but if it does and you get that working, you'd be my hero. ![]() |
|
#7
|
||||
|
||||
|
Re: Rookie programmer in need of help.
if what Ryan M. says about kshot's objectives is true, the simplest way would probably be with a finite state machine and a variable to determine if the robot is in a 'wait' state.
|
|
#8
|
|||||
|
|||||
|
Re: Rookie programmer in need of help.
Quote:
However, if you're refering to scripting (or any other high-level, multi-cycle sections), than this is entirely possible. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A ? about NASA grants | computhief263 | General Forum | 18 | 29-03-2004 13:35 |
| Rookie Regionals | rachakate | Regional Competitions | 5 | 24-03-2004 00:01 |
| TEAM 121 and a rookie team on CBS SAT MORNING! | Joe Menassa | General Forum | 7 | 21-03-2002 00:47 |
| Rookie Programmer has question about the default code | DanL | Programming | 3 | 26-01-2002 19:59 |