Question

In: Computer Science

In Python, Define an object-oriented class to represent a Sensorless Wheeled Robot, including: (a) class data...

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

Solutions

Expert Solution

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.


Related Solutions

The assignment is to write a class called data. A Date object is intented to represent...
The assignment is to write a class called data. A Date object is intented to represent a particuar date's month, day and year. It should be represented as an int. -- write a method called earlier_date. The method should return True or False, depending on whether or not one date is earlier than another. Keep in mind that a method is called using the "dot" syntax. Therefore, assuming that d1 and d2 are Date objects, a valid method called to...
Python Please Define a class that will represent soccer players as objects. A soccer player will...
Python Please Define a class that will represent soccer players as objects. A soccer player will have as attributes, name, age, gender, team name, play position on the field, total career goals scored. The class should have the following methods: 1. initializer method that will values of data attributes arguments. Use 0 as default for career goals scored. 2. str method to return all data attributes as combined string object. 3. addToGoals that will accept an argument of int and...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
Develop a python program to autonomously operate an adeept tank robot to pick up an object...
Develop a python program to autonomously operate an adeept tank robot to pick up an object placed randomly in an arena.
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields:...
[20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method...
5. [20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data...
5. [20 marks] (TestRobot.java) Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction number (0 for east, 1 for south, 2 for west, and 3 for north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = 0. Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors...
Design a class named Robot. The Robot class has three private data fields: position x, position...
Design a class named Robot. The Robot class has three private data fields: position x, position y, and the direction (east, south, west, and north). Assume that positive x points to the east and positive y points to the south, and initially x = 0, y = 0, direction = "east". Create a no-arg constructor and another constructor which sets the three data fields. Create the accessors and mutators for the three data fields. Create a method named forward that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT