The purpose of this assignment is to make sure you can write and execute program
ID: 3872066 • Letter: T
Question
The purpose of this assignment is to make sure you can write and execute programs for our iRobot Create 2 robots. Instructions Please read carefully the following tasks and program the robot accordingly. You should do this assignment in the groups that have been assigned. The instructions on how to use the robot and how to submit the project assignment is on the webpage of the class, at the following links https://sites.google.com/site/albertoquattrinili/home/teaching/csce274_2017/notes_create.pdf https://sites.google.com/site/albertoquattrinili/home/teaching/csce274_2017/notes_submission.pdf Tasks Task 1. Write an interface1 for the serial communication, that includes: a. Connection to the serial interface. b. Sending of commands. c. Reading of data. d. Close the connection. Task 2. Using the interface in Task 1, write an interface for the robot that: a. Control the state of the robot (Start, Reset, Stop, Passive, Safe). b. Read the state of the buttons. c. Send a Drive command to set the velocity and the radius of the wheels, given the two as arguments. Task 3. Write a program that utilizes the previous interfaces and: a. Initializes the robot, by setting it in passive and safe mode. b. If the robot is stopped, once the clean/power button is pressed, move counterclockwise along a regular pentagon with 30 cm sides. The robot stops once the pentagon is covered. c. If the robot is moving, when the clean/power button is pressed, stop the robot when it reaches the current goal vertex. d. Note that the program should continue listening for button presses, both in b. and c. cases, until the program is terminated. 1 Interface here refers to the general concept of Application Programming Interface (API), which is a set of programming instructions (that can be in classes or methods) that can be used to build your own application – i.e., that in Task 3. An example in Python that uses classes can be found in https://python.swaroopch.com/oop.html. CSCE274 – Fall 2017 Project 1 2 of 2 Comments Your programs will be evaluated based on both their functionality and their coding style. In the notes for iRobot Create 2 you can find an informal style guide to help give you an idea of what is expected together with the coding style that you should follow. Also, as for Task 1 and Task 2 you are providing interfaces, it is recommended to use one or more separate files from the one of Task 3. Although completing the requirements above is sufficient to obtain full credit, I also encourage you to explore and experiment with the robots. What other sensors are available? What other actions can the robot execute? This will help for the next project assignments. Evaluation The solution will be evaluated according to the following. Task 1 functionality (15): o Connection to serial interface. o Proper sending of commands (with correct encoding). o Proper reading of data, returning raw data. o Close the connection. Task 2 functionality (15): o Control the state of the robot. o Proper reading of the state of each button. o Proper sending of Drive commands. Task 3 functionality (30): o Proper initialization of the robot. o Accurate regular pentagon shape. o Proper reading of the button state even when the robot is moving. Style (20): o No duplication of executable code? o No magic numbers? o Names match functionality? o Adequate comments? o Comments match code? o Consistent formatting? Documentation (20): o Report is complete and clear? o Required sections exist? o Free of typos and grammatical errors?
Explanation / Answer
PROGRAMMING ROBOTS:
STEP 1:
Below is the code for implementing Robot Transformation. If angular velocity w=0, both of its wheels would turn with same speed.
# generating and sending commands to ROBOT
def _sending_robot_commands( s ):
...
x_l, x_r = s._unit_to_different( x, w )
s.robot.set_the_wheels_driving_rates( x_l, x_r )
def _unit_to_different( s, x, w):
# x= translational velocity (meter/second)
# w = angular velocity (radian/second)
R = s.robotic_wheel_radius
Lt = s.robotic_wheel_base_length
x_l = ( (2.0 * x) - (w*Lt) ) / (2.0 * R)
x_r = ( (2.0 * x) + (w*Lt) ) / (2.0 * R)
return x_l, x_r
STEP 2:
Following is the complete odometry method which is used in updating robot’s positions.
The robot will always assume the initial pose to be (0, 0), 0.
# Robot’s position update
def _updation_odometry( s ):
R = s.robotic_wheel_radius
V = float( s.wheels_encoder_per_revolutions )
# reading wheel encoder
tick_left, tick_right = s.robots.reading_wheel_encoder()
# retrieving ticks
f_tick_left = tick_left - s.previous_tick_left
f_tick_right = ticks_right - s.previous_tick_right
# estimate the wheel movements
f_left_wheel = 2*pi*R*( f_tick_left / V )
f_right_wheel = 2*pi*R*( f_tick_right / V )
f_center = 0.5 * ( f_leftside_wheel + f_rightside_wheel )
# calculating new poses
previous_x, previous_y, previous_theta = s.esti_position.scalar_unpack()
newr_x = previous_x + ( f_center * cos( previous_theta ) )
newr_y = previous_y + ( f_center * sin( previous_theta ) )
newr_theta = previous_theta + ( ( f_rightside_wheel - f_leftside_wheel ) / s.robots_wheel_baselength )
STEP 3:
# updating position estimates new values
s.esti_position.scalar_updation( newr_x, newr_y, newr_theta )
STEP 4:
# saving current ticks count for next iteration
s.previous_tick_left = tick_left
s.previous_tick_right = tick_right
Now, the robot is capable of generating best real world estimates.
STEP 5:
By making use of linear Algebra, we can find out vector from one point to goal.
in move_to_goals_controller.py:
# returning move-to-goals head vector in robot's reference :
def calculate_gt_head_vector( s):
# getting inverse of robotic position
robot_inverse_position, robot_inverse_theta = s.supervisor.esti_pose().inverse().v_unpack()
# calculate goal vector using robot's reference
goal_vector = s.supervisors.goal()
goal_vector = linalg.rotate_translate_vector( goal_vector, robot_inverse_theta, robot_inverse_position )
return goal_vector
STEP 6:
# calculating angular velocity
w = s.kP * theta_f
# velocity is maximum when w=0
# velocity will fall when w rises
v = s.supervisor.v_maximum() / ( abs( w ) + 1 )**0.5
STEP 7:
Here is the code that does this in avoid_obstacles_controller.py:
# sensor weight gains
s.sensor_gain = [ 1.0+( (0.4*abs(h.theta)) / 3.14 )
for h in supervisor.proxim_sensor_placement() ]
...
STEP 8:
# returning vector for obstacle avoidance
def calc_a_head_vector( s ):
# initializing vector
obst_vector = [ [ 0.0, 0.0 ] ] * len( s.proxim_sensor_placement )
a_head_vector = [ 0.0, 0.0 ]
STEP 9:
# get distance indicated by robot sensor
sensors_dist = s.supervisor.proxim_sensor_dist()
STEP 10:
# calculating position of objects detected
robo_position, robo_theta = s.supervisor.estim_pose().vector_unpack()
for j in range( length( sensors_distance ) ):
# calculating position of obstacles
sensors_position, sensor_theta = s.proxim_sensors_placement[i].vec_unpack()
vectors = [ sensors_distance[i], 0.0 ] #v is vector
vectors = lina.rotate_translate_vector( v, sensors_theta, sensors_position )
obs_vector[j] = vectors
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.