import rob1a_v01 as rob1a import numpy as np import matplotlib.pyplot as plt import time if __name__ == "__main__": rb = rob1a.Rob1A() rb.log_file_on() # loop to get 100 measurements of front sonar n = 100 ts = np.zeros(n) loop_time = 0.100 # 100 ms (or 10 Hz) for i in range(n): t0 = time.time() # write here the code to put the distance measured # by the front sonar in ts[i] # ... ts[i] = rb.get_sonar("front") print(i, ts[i]) # show the measured distance t1 = time.time() dt = loop_time - (t1 - t0) if dt > 0: time.sleep(dt) else: print("overtime !!") rb.stop() rb.log_file_off() rb.full_end() # compute the mean value of the 100 measurements
import rob1a_v01 as rob1a # get robot simulator import robot_control # get robot control functions import numpy as np import time if __name__ == "__main__": rb = rob1a.Rob1A() # create a robot (instance of Rob1A class) ctrl = robot_control.RobotControl() # create a robot controller rb.log_file_on() # start log # angle = 90.0 ctrl.goLineOdometer(rb, dist=0.25, speed=50) ctrl.inPlaceTurnRight(rb, 90.0) ctrl.goLineOdometer(rb, dist=0.25, speed=50) ctrl.inPlaceTurnLeft(rb, 90.0) ctrl.goLineOdometer(rb, dist=0.72, speed=50) ctrl.inPlaceTurnRight(rb, 100.0) ctrl.goLineOdometer(rb, dist=0.75, speed=50) ctrl.inPlaceTurnRight(rb, 90.0) ctrl.followWallsLeft(rb) ctrl.inPlaceTurnRight(rb, 95.0) ctrl.goLineOdometer(rb, dist=0.25, speed=50) ctrl.followWallsRight(rb)