Thread: Help reading pseudo code for car robot

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    2

    Help reading pseudo code for car robot

    I'm doing a practice problem where I need to read pseudo code and understand what it does. I know some of it, but can someone read my logic for the pieces of code and tell me if they're correct?




    For this code, I believe it will move the robot forward while i<650, so it moves it forward for 650 steps in total. Then it sets the motors to 0 when it's finished.
    Code:
    while(i<650)
    { rotateCW(2);    
    rotateCCW(1);    
    Delay1KTCYx(50);
    i++;
    LATD=0x00;     //Set all Port D to 0
    }

    This code I'm having the most trouble with. So while(1) the pot(potentiometer) read's the ADC. Then it scales the adc, not 100% sure what the +20 and *.22 mean, I think it has to do with binary conversions?

    Now it sets pin 1 of port 1 to 0, delays based on pot above, and sets it back to 1, and delays again. I'm confused what this function is actually doing, I assume something to do with controlling motor speed based on the potentiometer.
    Code:
    void main(void){TRISD = 0x00;         // Setting port D to outputs
    LATDbits.LATD0 = 1;       // Setting bit 0 of port D to 1
    while(1)
    {              
    pot = readADC();
    pot = pot * 0.2297 + 20;
        LATDbits.LATD1 = 0;    
        Delay10KTCYx(pot);      
        LATDbits.LATD1 = 1;      
        Delay10KTCYx(pot);      
    }
    return;
    }

    My best guess is: The car moves forward 400 steps, stop, turn right for 230 steps, stop. At this point it would begin moving straight, and it would turn left/right as needed to keep the robot in the center of the track.

    Code:
    void main(void)
    {
    for(i=0;i<400;i++)
    {   
    rotateCW(2,motor);    //Rotate motor two (one step)
    rotateCCW(1,motor);    //Rotate motor one (one step)
    Delay1KTCYx(50);
    i++;
    LATD=0x00;     //Set all Port D to 0
    }
    i=0;
    while(i < 230)
    {
    rotateCW(2); // Rotate motor two by one step
    rotateCW(1); // Rotate motor by one step
    Delay1KTCYx(50);    // Changing the argument in the delay function will change the speed at which        
                                         // the motor rotates. Delay equals 1000 x 50 x 1/12 = 4.167 ms
    i++;
    LATD = 0x00;    
    }
    i=0;
    for (i=0;i<400;i++)
    {   
    SetChanADC (ADC_CH0);    
    ConvertADC();      
    while (BusyADC());    
    leftsensor = ReadADC();    If (leftsensor>400)
    {
    TurnRight(5);
    GoForwardx(1);
    }
    If (leftsensor<300)
    {
    TurnLeft(5);
    GoForwardx(5);
    }
    If (leftsensor<400)&&(leftsensor>300)
    {
    GoForwardx(5);
    i++;
    }
    }
    Last edited by connectrme; 09-12-2014 at 02:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pseudo Code
    By BretFlorida in forum C Programming
    Replies: 2
    Last Post: 04-15-2013, 03:13 PM
  2. robot code
    By pureflip428 in forum C Programming
    Replies: 2
    Last Post: 12-03-2012, 08:28 PM
  3. Writing to/Reading from Pseudo Terminals
    By davo666 in forum C Programming
    Replies: 2
    Last Post: 01-21-2009, 11:10 PM
  4. Pseudo TTY not reading singal character
    By MrUmunhum in forum Linux Programming
    Replies: 0
    Last Post: 11-18-2008, 07:02 PM
  5. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM