I Need More SimpleIDE Knowledge!!!!
![NWCCTV](https://forums.parallax.com/uploads/userpics/406/nWOV2NX1YHRZF.jpg)
I would like to expand my knowledge of SimpleIDE without having to spend hours studying. I want to program my Wild Thumper similar to the Boe Bot Roaming with Ping. I have code for controlling the WT with a remote, but I want to make it autonomous using Ping and IR sensors for now. What I really need to know is can I create "Goto" sections such as in PBasic or what? Will the Activity Bot Tutorials work if I am not using encoders?
EDIT: I think I can figure out how to use the Activity Bot code for Ping to get my WT going somewhat autonomously. I just need to know if I have to use 500 and below for my numbers using abdrive.h in the same way I had to with servo.h. and in Spin.
EDIT 2: I see now that it will not work using abdrive.h. So, I am going to play with the current code using servo.h and see what I can derive from it all.
EDIT: I think I can figure out how to use the Activity Bot code for Ping to get my WT going somewhat autonomously. I just need to know if I have to use 500 and below for my numbers using abdrive.h in the same way I had to with servo.h. and in Spin.
EDIT 2: I see now that it will not work using abdrive.h. So, I am going to play with the current code using servo.h and see what I can derive from it all.
Comments
Good question, I should probably add a tutorial about that. Really good question.
The general approach is to read your sensors in a loop, and then start with an if statement that deals with the most important sensor. Then the else if can deal with the second most important sensor, and so on. The thing about the code below that is important is if the robot needs to take an evasive maneuver because it detects an object with if(distance < 20), it ignores the remote code in (else if). But, if it there's nothing too close, and you are holding a button, it'll go into the remote control code.
P.S. Two monitors is great for that. Even 20 minutes every couple days, and you'll notice improvements.
The example in post #5 gives the distance measurement priority with if(distance < 20). If the distance is less than 20, it takes evasive maneuvers and doesn't pay any attention to the IR navigation decisions in the else if part. On the other hand, if the distance is greater than 20, it will continue to the else if. Since it's else if(remoteCode != -1), you have to be pressing a button for any of the nested if...else if... code to get executed. If you're not pressing a button, the loop repeats. If you are pressing a button, it goes into the code that checks which button and takes maneuvering action based on that.
This provides an example of the difference between if...else if... and just having a bunch of if... statements. If...else if... exits the entire sequence after it has found and responded to a true condition. In contrast, a bunch of if statements all get checked, and whatever is true gets executed.
Andy
http://learn.parallax.com/activitybot/roaming-ultrasound
I seriously recommend using indentation like Andy did to keep your code readable.
The only problem I have with that is the forums penchant for adding two newlines for every blank newline.
There's a lot more grunt work happening under the hood. One example is that the servo_set call (all roads lead to servo_set) always checks to see if a cog has been launched for servos already. If it has not, the servo_set function does that first. The next time servo_set gets called, it checks, but finds out that the cog has already been started, so it just updates the values the cog needs to make the servo do what servo_set wants. There is also additional work behind the scenes so that your code can say servo_set(14, 2000), servo_set(15, 1000), which is what happens when you call drive_speeds(500, 500) -assuming drive_pins(14, 15). When servo_set sees that second call with pin = 15 instead of pin = 14, if figures out that it's a different pin from last time and sets up a memory slot for the information the cog will need to send control signals to that second servo.