Using '>=' or logic gates ('&&, OR, NOT, etc) in a variable - Possible???

Below code illustrates what I’m trying to do, but to summarize, I’m trying to use a variable to replace the logic gates (OR, NOT, &&, etc), or the equals part of an if statement. (==, >=, <=).

int variable_1 = 45;
char equals_1 = ">=";
char equals_2 = "<=":
char logicGate = "&&"";

Serial.begin(9600);

//if ((variable_1 >= 40) && (variable_1 <= 50))

if ((variable_1 equals_1 40) logicGate (variable_1 <= 50))
{
  Serial.print("works");
}

Background is I’m trying to develop code for a robot that loads an array of ints out of a SD card, one line at a time, and converts each line into a command, along with a trigger that ends that command.

For example, one line might convert to ‘Run left motor at 255 and right motor at 200 until 2 seconds have passed, or your heading is less than 180 degrees’.

3rd int in the array represents what the trigger variable is (in this case, one of the axis of an electronic compass, 4rth int determines if it needs to be ‘>=’, ‘==’ or ‘<=’, and 5th line is the number it’s compared to. (180, in this case). Then more int’s determine the second trigger, it’s length, and what logic gate connects it to the first.

At the moment though, I don’t know if it’s even possible, as I’ve written it in the example code. I could possibly use a set of functions for each one

(if receivedArray[3] == 1, run lessThan() function), etc

, but I can see that ending up as a maze of functions cross refferncing each other, and there’s got to be a better way.

Is there? Can anyone point me in the right direction?

Sounds to me like you want to store a "robot control" program on the SD card.

If so, that has been done many times, and interpretive languages have been invented for the purpose.

The simplest approach is to write a bunch of functions that carry out the basic operations, and encode commands as text lines, e.g. "F25R90F100" could be forward 25 steps, turn right 90 degrees, forward 100 steps.

A control program running on the robot reads the text lines and interprets them to carry out the actions. Of course, you can test sensors and carry out conditional actions in such a scenario, but it requires some careful planning (or google for what other people have done).

jremington:
Sounds to me like you want to store a "robot control" program on the SD card.

Pretty much.

jremington:
...and encode commands as text lines, e.g. "F25R90F100" could be forward 25 steps, turn right 90 degrees, forward 100 steps.

Hmm, I can see how that'd be easier - and take up less space than using ints. It was kind of bugging me that some of the ints were only being used to convey 3 or 4 different states, when they could store thousands.

jremington:
Of course, you can test sensors and carry out conditional actions in such a scenario, but it requires some careful planning (or google for what other people have done).

It certainly wouldn't hurt to check what others have done. I'd describe myself as a beginner programmer anyway, and this is pushing up against my limits. Which is the best way to learn, of course, but maybe the better way is to see how others have done it.

Check out the wildly popular, programmable Big Trak toy tank, from 1979!

Thanks, had a breif look after my last post, but didn't really know the right search terms. I'll check that out after work.