Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need c-program for both experiment-1 and experiment-2. Lab Assignment 8- Robot

ID: 3589963 • Letter: I

Question


I need c-program for both experiment-1 and experiment-2. Lab Assignment 8- Robot Driving Points: 10 EQUIPMENT: Mobile Robot with Embedded Controller incl .PSD sensors and motors EXPERIMENT 1 (4 points) The robot is starting in a random position and orientation near the middle of the driving area. The task is to drive the robot straight and collision-free close to the wall in front, then turn to the right, so it is parallel to the wall (at the robot's left-hand side) in about 15cm distance. EXPERIMENT 2 (6 points) With the robot placed alongside one of the walls of the driving area in 15cm distance, drive one complete (and collision-free) loop around the driving area always keeping a similar distance to the wall on the left-hand-side of the robot.

Explanation / Answer

Save this file in robot.c, compile and run. Try to understand the code. 2nd function is in a infinite loop, try to figure out a way to complete only one loop for the robot to cover. You can modify the code as required. If any query put a comment.

/**************************/

/*
* robot.c
*
* Created on: 12-Oct-2017
*      Author:
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

#define PI 3.141
int straightMovement(int* curpos,int defang);
void loopMovement(int* curpos,int defang);
int area[4][2]={{0,0},{0,100},{100,100},{100,0}};
int main()
{

   srand(time(NULL));
   int curpos[]={25+rand()%50,25+rand()%50};
   int curang=rand()%360;
   printf("Currpos before movement:{%d,%d} ang: %d ",curpos[0],curpos[1],curang);
   int retang=straightMovement(curpos,curang);
   printf("Currpos after straight movement:{%d,%d} ang: %d ",curpos[0],curpos[1],curang);
   loopMovement(curpos,retang);
   return 0;
}

int straightMovement(int* curpos,int defang)
{
   double angrad=(double)defang*PI/180.0;
   double x=curpos[0], y=curpos[1];
   double r=0.1;

   while(x>=15 && x<=85 && y>=15 && y<=85)
   {
   x=x+r*cos(angrad);
   y=y+r*sin(angrad);

   }
   curpos[0]=x;
   curpos[1]=y;

   int transang=defang-45;
   transang=transang/90;
   return transang;

}

void loopMovement(int* curpos,int defang)
{
   int x=curpos[0], y=curpos[1];
   while(x>=15 && x<=85 && y>=15 && y<=85)
   {
   if(defang==0)
       y--;
   else if(defang==1)
       x++;
   else if(defang==2)
       y++;
   else
       x--;

   if(x==85 && y==15)
       defang=3;
   else if(x==15 && y==15)
       defang=2;
   else if(x==15 && y==85)
           defang=1;
   else if(x==85 && y==85)
           defang=0;

   printf("x: %d, y: %d ",x,y); // Find a way to count one complete cycle (try it yourself)
                                   // this will go in infinite loop, means, robot will continuously make a loop

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote