How Do I Integrate External Functions into My Robot's Square Path Program?

In summary: ThanksNo, it just makes the robot make a right turn before waiting. Should the robot wait before turning right?Yes, it should wait.
  • #1
Hooke's Law
30
0

Homework Statement



I want a robot to roll in a path with 4 sides or in other words square, so I made a possible program but I am not sure if it will work. And how do you call 2 source codes into a different code like the one below? ( the 2 are right.hex and the other is DelaySpeed )

right - causes the robot to make a right turn
DelaySpeed - controls the speed of the motor of the robot ( steps / sec )

The Attempt at a Solution



Note: DelaySpeed() and right() are not in the same code. So how do I call the 2 functions in this code?

Fragment of the code :
Code:
int main(){
     int n = 0;
     while ( n < 5 ){
         right();
         DelaySpeed();
         n++;
     }
          
return 0;
}
Thanks
 
Last edited:
Physics news on Phys.org
  • #2
You could simply copy the function definitions and declarations for right() and DelaySpeed() into this file. Or, if those function declarations reside in a header, then you could include that header file.

Question: does DelaySpeed determine how long the robot will travel for, and is that how long it takes for the function to return? Because if there is no delay before that function returns, then right now, there is nothing controlling how long the robot travels after making a right turn.

EDIT: by the way, right now your while loop will run 5 times, meaning that the robot will make 5 right turns. This is because n starts at 0.
 
  • #3
You can also link different source files together when compiling using gcc. It seems to be fairly well-explained here:

http://www.network-theory.co.uk/docs/gccintro/gccintro_12.html

EDIT: Actually hit previous to go back to sec. 2.3 of that book for some more background.
 
  • #4
cepheid said:
Question: does DelaySpeed determine how long the robot will travel for, and is that how long it takes for the function to return? Because if there is no delay before that function returns, then right now, there is nothing controlling how long the robot travels after making a right turn.

Do you mean the robot must stop first then make a right turn?

this is a part of the right turn code

Code:
void turnRight(int stepNum){
	
	int i = 0;

	while(i<stepNum){
		rotateCW(2);																							// Rotate motor two step
		rotateCW(1);																							// Rotate motor 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;																							// Set all port D to 0	
	}

	return;
}

Thanks
 
  • #5
so if I am interpreting this correctly, right() causes the robot to turn right. DelaySpeed() then tells the robot to wait before making the next turn?

Also, you may want to look into using a 'for' loop. (You may already know this)
It's like this:

Code:
for(int n = 0; n < 5; n++)
{

}

Which would perform the exact same function as your while() loop.
 
  • #6
julz127 said:
so if I am interpreting this correctly, right() causes the robot to turn right. DelaySpeed() then tells the robot to wait before making the next turn?

Also, you may want to look into using a 'for' loop. (You may already know this)
It's like this:

Code:
for(int n = 0; n < 5; n++)
{

}

Which would perform the exact same function as your while() loop.

No, it just makes the robot make a right turn before waiting. Should the robot wait before turning right?
 
  • #7
Yes, it should wait.

Otherwise it will be continually trying to turn right.
 
  • #8
How do you make a robot wait?

I was thinking making a function called "Wait(time)", where "time" is 1/1000 of a second. Do you shut down a robot for that time to make it wait?

Thanks
 
  • #9
In my limited experience working with micro controllers, usually they have a delay() or delayms() function in their library. So suppose you wanted a robot to drive forward for 5 seconds, you'd set the current to the motor 'high' then delay(5).

The actual wait is done by loops, google "assembly nested loops" if you want to see how it's done.
 
  • #10
You could just use sleep() or usleep() as well, I think that these are standard functions, are they not?

The best thing would be if there was some sort of signal that the motor (or controller) gave out once the motor had stopped moving. That way your wait time would be exactly as long as the straight line motion that occurred after each turn.
 

FAQ: How Do I Integrate External Functions into My Robot's Square Path Program?

What is "Programming (Square Pattern)"?

"Programming (Square Pattern)" is a method of writing instructions for a computer to create a pattern using squares. This can be done using various programming languages such as Java, Python, or C++.

How does "Programming (Square Pattern)" work?

Programming (Square Pattern) works by using a series of commands or instructions to tell the computer how to draw squares in a specific pattern. The instructions are written in a programming language and are executed by the computer to create the desired pattern.

What are the benefits of learning "Programming (Square Pattern)"?

Learning Programming (Square Pattern) can improve logical thinking and problem-solving skills. It also allows for the creation of unique and intricate patterns that can be used for various purposes, such as graphic design or data visualization.

Can anyone learn "Programming (Square Pattern)"?

Yes, anyone can learn Programming (Square Pattern) with dedication and practice. It may be challenging for beginners, but with persistence and a willingness to learn, anyone can become proficient in creating square patterns using programming languages.

What are some resources for learning "Programming (Square Pattern)"?

There are many online resources available for learning Programming (Square Pattern), such as tutorials, videos, and interactive coding platforms. Some popular resources include Codecademy, Khan Academy, and Coursera. Additionally, many books and courses are available for purchase.

Similar threads

Replies
12
Views
2K
Replies
7
Views
2K
Replies
2
Views
3K
Replies
15
Views
2K
Replies
3
Views
1K
Replies
23
Views
3K
Back
Top