I need to write a right turn code for a micromouse using sensors but I don't know where to start. Can you help me please? This is the algorithm we developed.

// Right turn while sensor 1 is OFF //

    initialize RTcounter = 0;
    if (sensor 6 == 0) {
        RTcounter++;
        if(sensor 6 == 1)
            RTcounter++;
            if(sensor 9 == 0)
            RTcounter++;
            if(RTcounter == 3)
                right_turn();
                reset RTcounter=0;
    }

// Right turn while sensor 1 is ON //

if(sensor 1 == 1) {
    straight();
    initialize RTcounter = 0;
    if (sensor 6 == 0)
        RTcounter++;
        if(sensor 6 == 1)
            RTcounter++;
            if(sensor 9 == 0)
            RTcounter++;
            if(RTcounter == 3)
                right_turn();
                reset RTcounter=0;
}

I know that I need to declare values for the revolutions. But how do I start to write the functions. Help me please. Thank you.

This is what I have so far. Please help me.

#define RTcounter 0
#define Right_THRESH 100
#define Front_THRESH 75
#define Turn_cycles 18

include <stdio.h>

int sensor 1;

while (sensor1 == 0)    //OFF
{

    if(sensor6 == 1)
        { RTcounter++ ; }

    else
        { RTcounter++ ;}

    if (sensor9 == 0)
        { RTcounter++ ; }


    void Turn_Right(int cycles, int direction)
        {

    if (direction == 1) //right
        {

    start_process(Motor(INPUT LATER));

    if(cycles == 18)
    {  Turn_cycles = 17;  }

    else 
    {  Turn_cycles = 18;  }

        }       
            }

    if(RTcounter == 3)
    reset RTcounter;            
                }

while (sensor1 == 1)
{
    void Move(int cycles, int direction)
    {   if (direction == 0) //forward

        start_process(Motor(INPUT LATER));
        Motor (INPUT);
            }

if(sensor6 == 0)
{  RTcounter++ ; }

else
{ RTcounter++ ;}

if (sensor9 == 0)
{ RTcounter++ ; }


    void Turn_Right(int cycles, int direction)
        {   if (direction == 0) //right
        {
            start_process(Motor(INPUT LATER));
            Motor (INPUT);

if(cycles == 18)
{  Turn_cycles = 17;  }

else 
{  Turn_cycles = 18;  }
                }
                    }

            if(RTcounter == 3)
                reset RTcounter;
                                }

You ask for help, but we don't have the info from you, to help you. I know you don't want to spend the time to write up the specifics, but really, we have very little idea of what command does what, and how much, on your robot.

You haven't even described WHAT your problem really is, and what your changes have made in the performance of the robot, etc.

That's where forums that rely on written data, frequently can fail - it's a lot of work just to communicate the problem

But it must be done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.