First of all, we need to establish how your program flows.
Does it execute one command, wait, then execute the next command? Or does it execute commands simultaneously? (for example, move and do something else)
I imagine you will want it to execute commands in sequence, rather than some complex threading which your motor system may not support.
In order to get your robot to move slowly, I would suggest creating a Move() method that takes a parameter, the amount of time you want it to spend moving, like this:
public void Move(int numberOfSeconds)
{
while (numberOfSeconds > 0)
{
myRobot.MotorOn();
Thread.Sleep(2000);
myRobot.MotorOff();
Thread.Sleep(500);
numberOfSeconds -= 2;
}
}
It's not exact, but that is one way of doing it.
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 your program flow questions, you may want to think of it as a list of instructions:
MOVE FORWARD
STOP
CHECK FOR OBJECT
ROTATE TO AIM AT OBJECT
MOVE FORWARD
STOP
etc.
So in your main program control loop, assuming the calls are synchronous (ie. your program stops while it is executing a command, like in the above Move method), you could simply have a bunch of IF statements (or a switch)
public void Main()
{
// What calculations should the robot do?
If (someCalculations == someValue)
{
// Rotate the robot to face the object
robot.RotateRight(10);
}
else if (someOtherCalculation == someValue)
{
// We are on course, so move forward
Move(10);
}
}
That might help you get started.
If however, your robot is asynchronous, that is, the code keeps running while the robot is doing things (such as you constantly getting feedback from the motion sensors) you will have to structure your program differently. The Move() method may still work, but your program flow should be slightly different. You can use a variable to keep track of the state:
public enum RobotStates
{
Searching,
Waiting,
Hunting,
Busy,
}
Then in your main loop, you can examine the state:
if (myRobotState != RobotStates.Busy)
{
// Do something
}
Remember to change the state when your actions complete.
It's entirely possible you will have to use threading for an asynchronous solution, so your method that receives feedback from your sensor doesn't get stuck waiting for the robot to move, but can continue to poll. Threading is beyond the scope of this answer though, but there are plenty of resources out there.