![]() |
If statement in .h file or Indirect addressing? Kevin NAV code...
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:
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... |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
You want the struct you use to be one of a predefined set, that is selected at the beginning of runtime? You could try a big switch() statement that would contain assignment statements.
Code:
struct commands mycommand;I wouldn't use a pointer to an array element because you'd be allocating space for structs that would not be used - you wouldn't switch modes after starting the process. |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
Example: .h file: Code:
struct commands command_list_drive_straight[] = {Code:
struct commands* cmd_list = NULL;Quote:
|
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
Yeah, yeah...great fixer-her-upper. What we got Dave is some thumbwheels from digikey connected to the four inputs on a joyport. Using BCD (0-9), we can run up to 99 different automodes with eight inputs on two ports. I'll give your example a shot and see what we come up with...PS thanks alot for sharing your thoughts. Next on the list is shaving more program FAT. Every time we turn around we are at our 32K limit...yuck...We aren't ready to get rid of the printf statements, we need those to debug but if it keeps it up, we are going to have to dump some printf to get more code packed in... |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
|
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Hey DAVE...
We just wanted to tell you this worked like a champ...BUT..holey-moley...does it eat up some program space... With the default struct command, we had 23K of program space left to mess with. Then we did your suggestions, and we duplicated the struct with three sets to represent three different automous modes, after we done that we now have 28K of complied program...whew... That was a big hit in our software... Anyway though, it worked like a champ, exactly what we need in conjuction with our thumbwheel 0-9 BCD (binary coded decemical) input wheels. |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
|
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
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 |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
I was pretty excited about the scripting idea. I modified the system to allow multiple "scripts" in the one array. I even allowed scripts to call other scripts, subroutine-like. This took a lot of time to get working, but I figured I we would write a short 4-6 command script for each of a dozen different autonomous programmes, and life would be grand.
But by the time I got up to about 7 scripts, the linker said it couldn't fit the array. I even tried breaking the array up into multiple arrays, but the linker was still upset. I posted a question about modifying the linker script, but, so far, no responses. Realizing that there is far less RAM for data like script arrays than there is memory for program storage, I threw out my wonderful scripting system and I plan to implement a nested-state machine system. There's still, what? a week left? -Norm :ahh: |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
|
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
Quote:
Something that might be worth considering is using the EEPROM to store your autonomous programs to get them out of Flash - you'll have to use the EEPROM code that someone posted on here last year though and it would generally be painful, but it would free up some space. |
Re: If statement in .h file or Indirect addressing? Kevin NAV code...
This is some really good stuff guys. Thanks for posting information and sharing your ideas. I'll have to try this when I get back, I am out of town on business away from the team right, bad timing to have to leave on business for the "real" job on the last week of the build season...
Anyway, we have done pretty much what Dave has suggested: Code:
if(thumbwheel == 0)Then our command list looks something like this...I won't post them all, but you can see how the flow goes. Code:
//do nothing but sit here and look pretty |
| All times are GMT -5. The time now is 23:59. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi