First of all, we need to establish how your program will work.
Does she execute one command, wait, and then execute the next command? Or does he execute commands at the same time? (e.g. move and do something else)
I assume that you want it to execute commands sequentially, and not some complex thread that your motor system may not support.
To make the robot move slowly, I would suggest creating a Move () method that takes a parameter, the amount of time you want to spend moving, for example:
public void Move(int numberOfSeconds) { while (numberOfSeconds > 0) { myRobot.MotorOn(); Thread.Sleep(2000); myRobot.MotorOff(); Thread.Sleep(500); numberOfSeconds -= 2; } }
This is not accurate, but it is one way to do this.
If you then call Move (10), for example, your robot will move for 10 seconds and pause every 2 seconds for half a second.
Regarding questions about the flow of your program, you can think of it as a list of instructions:
MOVING FORWARD STOP CHECK FOR OBJECT ROTATE AIM FOR OBJECT TO MOVE FORWARD STOP
and etc.
So, in your main program control loop, assuming the calls are synchronous (i.e. your program stops during the execution of the command, as in the Move method above), you can just have a bunch of IF statements (or a switch)
public void Main() {
This can help you get started.
If, however, your robot is asynchronous, that is, the code continues to work while the robot does something (for example, you constantly receive feedback from motion sensors), you will have to structure your program in different ways. The Move () method may still work, but your program flow should be slightly different. You can use a variable to track the status:
public enum RobotStates { Searching, Waiting, Hunting, Busy, }
Then in your main loop you can check the status:
if (myRobotState != RobotStates.Busy) {
Remember to change the state when your actions are completed.
It is entirely possible that you will have to use threads for an asynchronous solution, so your method, receiving feedback from your sensor, does not get stuck waiting for the robot to move, but can continue to poll. However, Threading is beyond the scope of this answer, but there are many resources.