keysle:
I haven't touched Arduino bots yet, I also haven't downloaded any of the associated code.
I will soon.
Is there some sort of emulator I can use to get some practice?
Does the language (that is similar to C++) have a test feature that I can use without the bot?
I just want to write the code before I get the bots so I can hit the ground running.
This could be done, but honestly it works best if:
- You have a ton of coding experience
- You are excellent at visualizing using abstractions
- You have at least some electronics experience (and maybe some tools - a frequency counter and/or an oscilloscope might help)
- You plan on designing and building the robot from scratch, or...
- ...you know exactly how to interface to the robot platform you are coding for
- You have the patience of a saint...?
At it's simplest, you need to decide on what you want the robot to do, then abstract and "black-box" each of the functions to accomplish those tasks in your code. Let's say you know the following:
- The robot is a differentially steered device
- You can use PWM to control the motors
- It has a servo which pans an ultrasonic sensor
- The ultrasonic sensor has (or you'll write) a library for it
So - you can figure you'll need the following functions (this is all high-level abstraction here - not real code):
1 - stop()
2 - forward(speed)
3 - reverse(speed) - note: alternatively, you could make a "move(speed)" function, where speed is a positive/negative amount - to replace both these functions
4 - left(speed)
5 - right(speed) - note: same here, except call it "turn(speed)"...
6 - panSensor(angle) - moves servo with ultrasonic sensor to some angle
7 - readSensor() - pings and returns a distance value from the ultrasonic sensor
From there, you would start implementing your functions to do what you need to do - but instead of motors being attached to the pins or whatnot, you would attach LEDs (with current limiting resistors, of course!) to the pins needed for PWM. You might actually hook up a real servo; for the sensor read portion, maybe you substitute in a potentiometer and use the Arduino's map() function to scale things appropriately as necessary.
As you develop the functions, you observe the output of the LEDs, the servo, and your simulated input of the "sensor" via the potentiometer. For some things (like stop(), forward(), reverse(), left(), and right(), for instance) - you only need the LEDs on those pins, which would eventually be hooked up to an h-bridge controller. Watch the brightness level of the LEDs to "guess" if it looks correctly (alternatively, hook up the outputs to a frequency counter or oscilloscope). Once you know that the PWM is working ok, force it to 100 percent all the time, then make sure that when the "forward()" LED is on, the "reverse()" LED is off, and vice-versa. Do the same for left(), right(), and stop().
After that, move on to controlling the servo; once you know you can command the servo to a proper position, simulation of the ultrasonic sensor is next. Doing this piece won't be easy, but you can gain a good idea of how your code will work, and whether it will work "mostly" properly.
Then - when you get your hardware purchased or built, you can plug it in to your board, and start the real testing; once you know your "black-box" functions all work properly, you can continue on with commanding those functions from your actual code which controls the robot. Just take it one step at a time, making sure each piece works before moving to the next (and don't get hasty or impatient, and try to implement it all at once - that can be a recipe for disaster; resist this understandable impulse, and do things in a plodding but methodical manner; you'll get much further with less problems that way).