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.

Kshot,

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)?

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.

See page 11 of 2004-programming-reference-guide-12-apr-2004.pdf (at the bottom of Perform Operations Example)for an example of how to reference a digital input. In this case, they use rc_dig_in01 to decide what to do (will the roller stop or go?).

You would need to connect your switch to digital input #1 on the robot controller for this to work.

Does this 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:


// 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:

#define  MY_SWITCH rc_dig_in15  // makes the other code easier to read

In the function Default_Routine(void), add your code like this:

near the top

static unsigned char switchWasHit = 0;

later:

// 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
  */
}


Remember that Default_Routine(void) is executed over and over again, about 39 times a second.

Does that 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. :smiley:

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.

If you’re refering to every line of C, than yes it would be, because data has to be returned to the master processor in a timely manner.

However, if you’re refering to scripting (or any other high-level, multi-cycle sections), than this is entirely possible.