View Single Post
  #8   Spotlight this post!  
Unread 14-02-2005, 11:27
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: If statement in .h file or Indirect addressing? Kevin NAV code...

Quote:
Originally Posted by chakorules
Ok...so I am not sure how to explain what I need but I know what I want to do.

I am helping our team program this year and really this is the first time I've dabble in C code. I normally program PLCs (programmable logic controllers)...anyway...

I noticed that Kevins nav code uses a commands.h file which is a structured something to send commands in a list format to the robot.c file. Very slick and easy. We've made our own functions and commands for our automous mode.

What I'd like to do is alter this with some inputs to create multi automous modes. We have all the inputs selections working but not sure what would be the best approach in C code to do what we need.

I want to do something like this:


Code:
if (input = 1)
    {
    struct commands command_list[] = {

    /*   Command              parm 1     parm 2   parm 3   */

    {CMD_WAIT,                 1000,        0,      0},
    {CMD_DRIVE,                1500,        0,      0},
    {CMD_WAIT,                 4000,        0,      0},
    }
};

Of course that's not exactly legal in C code....

So if I was doing this in a PLC, I might use what is called indirect addressing, or assigning a varaible to a pointer.

Like:

struct commands command_list*myvarible*[] =

so if myvarible is equal to 1 then run the commands in list #1. If myvarible is equal to 2 then run the commands in list #2.

Is there such a thing like this in C Code?

I hope that makes sense...

It does....another approach (which might save some memory space), is based on your thumbwheel positions, call a function which puts the dsitred command list into the structure. That way you'll just have one structure, not multiple copies.

Jon Mittelman
Mentor