Question: 2 . 1 Distance traveled by a robot We can estimate the total distance traveled by a robot by adding up the distances between consecutive
Distance traveled by a robot
We can estimate the total distance traveled by a robot by adding up the
distances between consecutive points on the trajectory of the robot. Here,
we only consider the x and y state variables but not the state variabe of
the robot. Given two consecutive points x y and x y their distance
is defined as dx yx y sqrtxxyy If a robot traveled through a sequence of points: x yx yx yxN yN ;
then the total distance that it traveled can be estimated as:
N
X
k
dxk ykxk yk dx yx ydx yx ydxN yNxN yN
Examples:
The distance between the two points and is d
sqrt meters.
If a robot traveled through points: to to to
; then its total travel distance is:
d d d meters
Tasks
Write a C program as follows:
It defines a new structure type with typedef named RobotState
that has double members: x y and theta. A structure of this
RobotState type represents a state of a robot.
It defines a new structure type with typedef named RobotControl
that has double members: v and w A structure of this RobotControl
type represents two control inputs v and w of a robot.
It defines a function named robot with the following prototype:
RobotState robotdouble T RobotState s RobotControl ctrl;
The function robot takes a discretization period T the current robot's
state s of type RobotState, and the current control inputs ctrl of
type RobotControl, to calculate and return as the function's output
the next robot state of type RobotState thats the return value of
the function The function robot can be used as in the following
example:
RobotState current ; x y theta
RobotControl u ; v w
RobotState next;
next robot current, u; Next state
Upon execution of the example code, by applying the robot's equations
in the previous section, the next robot state is x y
Hint: do not directly check whether a floatingpoint number equals
; instead, compare its absolute value to a small number, such as
e
if fabsswe
w can be considered zero
else
w can be considered nonzero
It definnes a function named distance with the following prototype:
double distanceRobotState s RobotState s;
The function distance takes two consecutive robot states s and s
and calculates and returns the distance between them as the function's
return value
The main function program does the following:
It reads from input the data and control sequences for possibly
several robots. The input has the following format:
robot
T x y theta
v w
v w
robot
T x y theta
v w
v w
Explanation:
The data for each robot begins with the string "robot followed by the name of the robot.
After that, the next line contains four floatingpoint numbers,
which are respectively the discretization period T and the
initial state x y and of that robot.
After that, the subsequent lines dene the sequence of control
input pairs vk wk for the robot, starting with k
one pair on each line. For example, the first pair are v and
w; the next pair on the next line are v and w; and
so on
The control sequence for the robot ends when a new robot
starts with the line "robot or when there is no more
input. The length of the control sequence is not known in
advance.
You can assume that each line of input will not exceed characters and that there are no more than robots dened in the
input. See the next subsection "Hints" for some hints on how to
process the input format.
Given the above data of possibly multiple robots read from the
input, the main program simulates the movement of each robot
similar to Phase using the robot function. For each robot,
the program must calculate and store the following values: its
name, its initial state, its nal state, its final time k T in
seconds and the total distance that it traveled.
typedef struct
Complete this struct definition
RobotState;
typedef struct
Complete this struct definition
RobotControl;
RobotState robotdouble T RobotState s RobotControl ctrl
Your implementation
double distanceRobotState s RobotState s
Your implementation
#define INPUTSIZE
#define MAXROBOTS
int main
Your main program
Example: If the input is
robot Opportunity
robot Curiosity
then the output is
Number of robots:
Robot Opportunity h
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
