What could be causing one wheel of my robot to not move?

  • Thread starter Thread starter DrDanger
  • Start date Start date
  • Tags Tags
    Motor
AI Thread Summary
The discussion centers on a programming issue related to controlling a robot's wheels using a microcontroller. The provided code includes functions for moving the left and right wheels forward, backward, and stopping. However, the user is experiencing a problem where only the left wheel operates, while the right wheel remains inactive. The issue is attributed to the use of two infinite while loops that prevent the program from executing the right wheel's commands. It is suggested to remove the first while loop to allow the program to cycle through the left wheel's movements before executing the right wheel's movements. Additionally, there is a humorous mention of the code being tampered with by a rodent and a comment about the robot's appearance resembling a Christmas tree, which is not intended. Overall, the main focus is on correcting the code structure to enable proper functionality of both wheels.
DrDanger
Messages
44
Reaction score
0
// first write the basic functionality for motion
void left_forward() {
PORTC.F0 =1;
PORTC.F1 =0;
}
void left_reverse() {
PORTC.F0 =0;
PORTC.F1 =1;
}
void left_stop() {
PORTC.F0 =0;
PORTC.F1 =0;
}

void right_forward() {
PORTC.F5 =1;
PORTC.F6 =0;
}
void right_reverse() {
PORTC.F5 =0;
PORTC.F6 =1;
}
void right_stop() {
PORTC.F5 =0;
PORTC.F6 =0;
}

void setup_P16F690() {
// This is all the stuff that's needed for the chip
ANSEL=ANSELH=0;
PORTC=0;
TRISC=0;
}

main() {
setup_P16F690();
while(1) { // Do this forever
left_forward();
delay_ms(1000); // Wait 1000 ms = 1sec
left_reverse();
delay_ms(1000); // Wait 1000 ms = 1sec
left_stop();
delay_ms(2000); // Wait 1000 ms = 1sec
}

while(1) { // Do this forever
right_forward();
delay_ms(1000); // Wait 1000 ms = 1sec
right_reverse();
delay_ms(1000); // Wait 1000 ms = 1sec
right_stop();
delay_ms(2000); // Wait 1000 ms = 1sec
}
}

I am new to programming just started learning it a few days ago. I wrote this for a robot I am working on and can't get the right wheel to move. The left one works fine. thanks for any help
 
Technology news on Phys.org
There is nothing to break out of the first while loop. The program is just going to cycle the left motor through the various modes for as long as the program runs. Perhaps you were thinking that these while loops ran in parallel, but they don't. They are run sequentially, but since the first while loop never exits, the program never gets to the second while loop.

Remove the while(1){ }'s from the program and it should do one left cycle, then one right cycle.
 
Well the Problem appears to be that program was tampered by a rodent, also the the robot seems to represent a christmas tree when it should rellay have no religous affliation. Other than that it looks good.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top