Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Compiled Languages > C   »   Can anyone explain the C program

 
Thread Tools Display Modes
Question
 
 
#1  
Old Nov 25, 2007, 11:54 AM
divya_nuthakki
New Member
divya_nuthakki is offline
 
Join Date: Nov 2007
Posts: 2
divya_nuthakki See this member's comment history on his/her Profile page.
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;
}

Reply With Quote
 
     

Answers
 
 
Old Nov 25, 2007, 12:05 PM   #2  
Full Member
asterisk_man is offline
 
asterisk_man's Avatar
 
Join Date: Nov 2006
Location: East coast of U.S.A.
Posts: 472
asterisk_man See this member's comment history on his/her Profile page.
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.
  Reply With Quote
 
     
 
 
Old Nov 26, 2007, 09:16 AM   #3  
New Member
divya_nuthakki is offline
 
Join Date: Nov 2007
Posts: 2
divya_nuthakki See this member's comment history on his/her Profile page.
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 im new for C programming. if possibl u can explain
  Reply With Quote
 
     
 
 
Old Nov 26, 2007, 11:19 AM   #4  
Full Member
asterisk_man is offline
 
asterisk_man's Avatar
 
Join Date: Nov 2006
Location: East coast of U.S.A.
Posts: 472
asterisk_man See this member's comment history on his/her Profile page.
i won't explain each line. i will answer specific questions you might ask though.
  Reply With Quote
 
     
 
 
Old Nov 26, 2007, 12:16 PM   #5  
Computer Expert
ScottGem is offline
 
ScottGem's Avatar
 
Join Date: Jan 2003
Location: LI, NY - USA
Posts: 23,907
ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.ScottGem See this member's comment history on his/her Profile page.
Pay to call ScottGem for advice ($.75/min)
Call ScottGem via Skype™
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.
  Reply With Quote
 
     


Thread Tools
Display Modes

 
Similar Sponsors

Similar Threads
Question Asker Forum Answers Last Post
can anyone explain this? jazzyfizzel_180 Music 2 Sep 17, 2007 07:46 AM
Could anyone explain? firmbeliever Other Health & Wellness 3 Sep 8, 2007 03:00 AM
can someone explain this to me woh337 Medical Specialties 3 Jul 4, 2007 08:50 AM
Can You Explain? Hope12 Christianity 7 Apr 30, 2006 06:02 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 02:00 AM.