In: Computer Science
In Python, Define an object-oriented class to represent a Sensorless Wheeled Robot, including:
(a) class data variables to store the robot’s x and y position.
(b) A class function or functions to move the robot by one distance unit in either positive or negative x, or positive or negative y dimensions. Include printed, informative output of each move and the resulting robot position
(c) A class function to navigate to the destination location by calling the class move functions (described above) • The destination object is passed in as a parameter to this function. • The obstacle position is also passed as a parameter to the function. • Reaching the destination does not require that the robot is rotated to ’face’ the destination in this model
class Sensorless_Wheeled_Robot:
def __init__(self, orig_x=0, orig_y=0):
self.orig_x,self.orig_y=orig_x,orig_y
def
move_robot_by_unit_distance(self,x=0,y=0):
if -1<=x<=1 and
y==0: # ONLY PASS X AND Y AS -1,0,1. SO THAT ROBOT MOVES BY UNIT
DISTANCE ONLY.
self.orig_x+=x
if x==0 and
-1<=y<=1:
self.orig_y+=y
print("position of robot
is: ",self.orig_x,self.orig_y)
return
(self.orig_x,self.orig_y)
def move_to_destination(self,des,obs): # des is
the list containing positions of destination .
print("moving towards
x")
# obs is the list containing positions of obstackle
if des[0]<0:
while(des[0]<self.orig_x ):
if (self.orig_x-1)==obs[0] and (self.orig_y)==obs[1]:
print("obstacle is detectedat :",obs[0],obs[1])
# if obstacle position is found right ahead of
robot then robot will go sideways avoiding the obstacle.
self.move_robot_by_unit_distance(0,1)
self.move_robot_by_unit_distance(-1,0)
self.move_robot_by_unit_distance(-1,0)
self.move_robot_by_unit_distance(0,-1)
else:self.move_robot_by_unit_distance(-1,0)
if des[0]>0:
while(des[0]>self.orig_x):
if (self.orig_x+1)==obs[0] and (self.orig_y)==obs[1]:
print("obstacle is detectedat :",obs[0],obs[1])
self.move_robot_by_unit_distance(0,1)
self.move_robot_by_unit_distance(1,0)
self.self.move_robot_by_unit_distance(1,0)
self.move_robot_by_unit_distance(0,-1)
else: self.move_robot_by_unit_distance(1,0)
if des[1]<0:
while(des[1]<self.orig_y):
if (self.orig_x)==obs[0] and (self.orig_y-1)==obs[1]:
print("obstacle is detected at :",obs[0],obs[1])
self.move_robot_by_unit_distance(1,0)
self.move_robot_by_unit_distance(0,-1)
self.move_robot_by_unit_distance(0,-1)
self.move_robot_by_unit_distance(-1,0)
else:self.move_robot_by_unit_distance(0,-1)
if des[1]>0:
while(des[1]>self.orig_y):
if ((self.orig_x)==obs[0] and (self.orig_y+1)==obs[1]):
print("obstacle is detected at ",obs[0],obs[1])
self.move_robot_by_unit_distance(1,0)
self.move_robot_by_unit_distance(0,1)
self.move_robot_by_unit_distance(0,1)
self.move_robot_by_unit_distance(-1,0)
else:self.move_robot_by_unit_distance(0,1)
print("final position of
robot is: ",self.orig_x,self.orig_y)
return
(self.orig_x,self.orig_y)


run the given code . there
mignt be some little changes in the comments and print statement as
I took screenshot then made some little changes for the better
understanding of code.If some problem occurs then don't panic, just
contact on the comment section . I will resolve the problem.