Looking for help in writing a code in C to make a rover follow commands includin
ID: 652802 • Letter: L
Question
Looking for help in writing a code in C to make a rover follow commands including moving forward at half inch increments up to 48'', and turning left and right up to 360 degrees in increments of 45 degrees. The rover is a ROV5-3 class rover with 4 motors and 4 encoders.
So far we are able to make the rover move, but are yet to figure out how to make it stop once it starts going. We are aware that it has to do with the ticks of the encoders, but cannot determine the C code. Our code so far is listed below, if anyone could help us fix it so the rover can move, turn, and stop at the intervals specified above it would help a lot.
#include "io_softcore.h"
#include "logicstart.h"
void both_forwards(){
LEFT_PORT_OUT=0x88;
LEDS=PINE;
int test=1;
while(test){
int prev=PINE;
int count=0;
prev=PINE;
if(prev!=PINE)
count++;
if(count>1)
PORTE=0x00;
return;
}
}
}
}
void left_off(){
LEFT_PORT_OUT= 0x3F;
}
void turn_right(){
LEFT_PORT_OUT= 0x48;
}
void turn_left(){
LEFT_PORT_OUT=0x84;
}
int main()
{
set_up_logicstart_io();
while(1){
int i;
i=0;
while(1){
if(i==0)
for(i=0;i<SWITCHES;i++){
both_forwards();
}
}
}
return 0;
}
Explanation / Answer
#include<io_softcore.h>
#include<logicstart.h>
void both_forwards()
{
LEFT_PORT_OUT=0x88;
LEDS=PINE;
int test=1;
while(test)
{
int prev=PINE;
int count=0;
prev=PINE;
if(prev!=PINE)
count++;
if(count>1)
PORTE=0x00;
return;
}
}
void left_off()
{
LEFT_PORT_OUT= 0x3F;
}
void turn_right()
{
LEFT_PORT_OUT= 0x48;
}
void turn_left()
{
LEFT_PORT_OUT=0x84;
}
int main()
{
set_up_logicstart_io();
while(1)
{
int i;
i=0;
while(1)
{
if(i==0)
for(i=0;i<SWITCHES;i++)
{
both_forwards();
}
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.