Ask Experts Questions for FREE Help !
Ask
    divya_nuthakki's Avatar
    divya_nuthakki Posts: 2, Reputation: 1
    New Member
     
    #1

    Nov 25, 2007, 01:54 PM
    Can anyone explain the C program
    #include <conio.h>
    #include <unistd.h>
    #include <dbutton.h>
    #include <dsensor.h>
    #include <dmotor.h>
    #include <sys/tm.h>
    #include <rom/system.h>
    #include <time.h>
    #include <stdlib.h>

    void motor_control(void);
    void forward_run(void);//20
    void direction_change(void);//20
    void obstacle_handling(void);//20
    void change_driving_command(int , enum dir_t, int, long int);
    time_t time0;
    enum dir_t{turn_left=0, turn_right, forward, backward, stop, puzzle };

    struct driving_command
    {
    int priority;
    enum dir_t direction;
    int speed;
    long int duration;
    }command;
    ////////////////////////////////////////
    // Main Function
    int main()
    {
    srandom(sys_time);
    command.priority = 0;
    command.speed= 200;
    command.duration = 100;
    command.direction = forward;
    time0 = sys_time;
    // Infinite Loop
    while(1)
    {
    forward_run();//20
    direction_change();//15
    obstacle_handling();//20
    motor_control();
    time0=time0 + 100;
    msleep(time0-sys_time);
    }
    return 0;
    }
    /////////////////////////////////////////////////////
    //Change Driving Command Function
    void change_driving_command(int prio, enum dir_t dir, int speed, long
    int dur)
    {
    if (command.priority <=prio)
    {
    command.priority = prio;
    command.speed= speed;
    command.duration = dur;
    command.direction = dir;
    }
    }
    ////////////////////////////////////////////////////
    //Obstacle Handling Function Uses Touch Sensors
    void obstacle_handling(void)
    {
    if (TOUCH_1 !=0)
    {
    change_driving_command(2,1,100,20);//(int prio = 3, enum dir_t dir =
    turn_right, int speed =100, long int dur = 25);
    }

    if (TOUCH_3 !=0)
    {
    change_driving_command(2,0,100,20);//(int prio = 3, enum dir_t dir =
    turn_left, int speed = 100, long int dur = 25);
    }
    }
    ///////////////////////////////////////////////////
    //Forward Run Function
    void forward_run(void)
    {
    change_driving_command(0,2,255,20);//(int prio = 0, enum dir_t dir =
    forward, int speed = 200, long int dur = 25);
    }
    ///////////////////////////////////////////////////
    // Directon Change Function Changes the direction of vehicle randomly
    void direction_change(void)
    {
    int enter = random()%15;
    int rnd;
    if (enter ==5)
    {
    rnd = random()%6;
    change_driving_command(1,rnd,150,15);//(int prio = 2, enum dir_t dir
    = rnd, int speed = 200, long int dur = 20);
    }
    enter=rnd;
    }
    ////////////////////////////////////////////////////
    // Motor Control Function Controlling the Motors Directly
    void motor_control(void)
    {
    if (command.direction==0) //Turning Vehicle Left;
    {
    motor_a_speed (command.speed);
    motor_c_speed (command.speed);
    if(command.duration>=15)
    {
    motor_a_dir(rev);
    motor_c_dir(rev);
    }
    else
    {
    motor_a_dir(rev);
    motor_c_dir(fwd);
    }
    }
    else if (command.direction==1) //Turning Vehicle Right;
    {
    motor_a_speed (command.speed);
    motor_c_speed (command.speed);
    if (command.duration>=15)
    {
    motor_a_dir(rev);
    motor_c_dir(rev);
    }
    else
    {
    motor_a_dir(fwd);
    motor_c_dir(rev);

    }
    }
    else if (command.direction==2)
    {
    motor_a_speed (command.speed);
    motor_c_speed (command.speed);
    motor_a_dir(fwd);
    motor_c_dir(fwd);
    }
    else if (command.direction ==3)
    {
    motor_a_speed (command.speed);
    motor_c_speed (command.speed);
    motor_a_dir(rev);
    motor_c_dir(rev);
    }
    else if (command.direction ==4)
    {
    motor_a_speed (command.speed);
    motor_c_speed (command.speed);
    motor_a_dir(brake);
    motor_c_dir(brake);
    }
    else
    {
    motor_a_speed (command.speed);
    motor_c_speed (command.speed);
    if(command.duration%2==0)
    {
    motor_a_dir(fwd);
    motor_c_dir(rev);
    }
    else
    {
    motor_a_dir(rev);
    motor_c_dir(fwd);
    }
    }
    if (command.duration>0)
    {
    command.duration = command.duration-1;
    }
    if(command.duration==0)
    {
    command.priority =0;
    }
    asterisk_man's Avatar
    asterisk_man Posts: 476, Reputation: 32
    Full Member
     
    #2

    Nov 25, 2007, 02:05 PM
    What sort of question is this? Either it's homework, in which case we don't do your homework for you but we can help with specific difficulties you're having, or... well I can't really think of anything else it could really be.
    divya_nuthakki's Avatar
    divya_nuthakki Posts: 2, Reputation: 1
    New Member
     
    #3

    Nov 26, 2007, 11:16 AM
    Quote Originally Posted by asterisk_man
    What sort of question is this? Either it's homework, in which case we don't do your homework for you but we can help with specific difficulties you're having, or ... well I can't really think of anything else it could really be.
    Hello,
    Its an programm given by our teacher. But I'm new for C programming. If possibl u can explain
    asterisk_man's Avatar
    asterisk_man Posts: 476, Reputation: 32
    Full Member
     
    #4

    Nov 26, 2007, 01:19 PM
    I won't explain each line. I will answer specific questions you might ask though.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #5

    Nov 26, 2007, 02:16 PM
    Quote Originally Posted by divya_nuthakki
    hello,
    its an programm given by our teacher. but im new for C programming. if possibl u can explain
    What about it don't you understand. Even if you are new, your teacher wouldn't have given it toyou if he didn't feel you could decipher it. Take it line by line and try to deciper it. If you have specific questions ask.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Can anyone explain this? [ 2 Answers ]

Hi my name is sagar. Let me tell you guys that I'm just a crazy fan of cradle of filth.and I've watched their one of the most greatest video Nymphetamine. But I couldn't figure out certain part of their lyrics. Here are they What is the meaning of " white lady laid"...

Could anyone explain? [ 3 Answers ]

When someone sleeps on his/her side,what effect will this have on the person's body? Also when we sleep on our stomach,does this effect our body while we sleep,does it restrict any of our organ functions etc? Another thing I wanted to ask was- When we drink water or other fluids, if we gulp it...

Can someone explain this to me [ 3 Answers ]

It is spelled like "peninectal abscesses", if I am right about it It was found like a tumor shape of thing inside the body(butthole).:( I am asking it for a family member, and I am worried about the person's health. :confused: What should be done with this illness? THank you!

Can You Explain? [ 7 Answers ]

Hello Everyone, (1 Corinthians 15:12) Now if Christ is being preached that he has been raised up from the dead, how is it some among YOU say there is no resurrection of the dead? John 11:11, 14-44: “ ‘Lazarus our friend has gone to rest, but I am journeying there to awaken him from sleep.’.....


View more questions Search