def start(self): self.device = torch.device('cuda') print('Loading model...') # create model self.model = torchvision.models.alexnet(pretrained=False) self.model.classifier[6] = torch.nn.Linear( self.model.classifier[6].in_features, 2) self.model.load_state_dict(torch.load(self.collision_model)) self.model = self.model.to(self.device) # create robot self.robot = Robot() print('Initializing camera...') # create camera self.camera = Camera.instance(width=224, height=224) print('Running...') self.camera.observe(self._update, names='value') def kill(sig, frame): print('Shutting down...') self.camera.stop() signal.signal(signal.SIGINT, kill) self.camera.thread.join()
def move(direction): robot = Robot() if direction == "forward": robot.forward(0.4) time.sleep(0.5) robot.stop() return render_template('index.html') elif direction == "left": robot.left(0.3) time.sleep(0.5) robot.stop() return render_template('index.html') elif direction == "right": robot.right(0.3) time.sleep(0.5) robot.stop() return render_template('index.html') elif direction == "backward": robot.backward(0.4) time.sleep(0.5) robot.stop() return render_template('index.html') else: return render_template('index.html') return render_template('index.html')
def __init__(self): self.camera = Camera.instance(width=224, height=224) self.robot = Robot() #Collision Avoidance self.ca_model = torchvision.models.alexnet(pretrained=False) self.ca_model.classifier[6] = torch.nn.Linear( self.ca_model.classifier[6].in_features, 2) self.ca_model.load_state_dict(torch.load('best_model.pth')) self.device = torch.device('cuda') self.ca_model = self.ca_model.to(self.device) self.mean = torch.Tensor([0.485, 0.456, 0.406]).cuda().half() self.std = torch.Tensor([0.229, 0.224, 0.225]).cuda().half() self.normalize = torchvision.transforms.Normalize(self.mean, self.std) #Road following support variables self.angle = 0.0 self.angle_last = 0.0 # Instantiating the road following network. self.rf_model = torchvision.models.resnet18(pretrained=False) self.rf_model.fc = torch.nn.Linear(512, 2) self.rf_model.load_state_dict(torch.load('best_steering_model_xy.pth')) self.rf_model = self.rf_model.to(self.device) self.rf_model = self.rf_model.eval().half() self.speed_gain = 0.12 self.steering_gain = 0 self.steering_dgain = 0.1 self.steering_bias = 0.0 self.t_unit_dist = 0.04 self.starttime = 0 self.cumulative_angle = -1 self.pitstop = [] self.startposition = [] self.pathpoints = [[]] self.proportionality_const = -1 # TODO : Add the proper value
def collision_avoidance(): global normalize, device, model, mean, camera, robot i_frame = -1 model = torchvision.models.alexnet(pretrained=False) model.classifier[6] = torch.nn.Linear(model.classifier[6].in_features, 2) model.load_state_dict(torch.load('best_model.pth')) device = torch.device('cuda') model = model.to(device) mean = 255.0 * np.array([0.485, 0.456, 0.406]) stdev = 255.0 * np.array([0.229, 0.224, 0.225]) camera = Camera.instance(width=224, height=224) normalize = torchvision.transforms.Normalize(mean, stdev) robot = Robot() robot.stop() now = time.time() stop_time = now + 120 while time.time() < stop_time: i_frame += 1 if i_frame % 2 == 0: update({'new': camera.value}) # we call the function once to intialize #cv2.imshow(camera.value) #camera.observe(update, names='value') robot.stop() camera.stop()
def main(): args = parse_args() cam = Camera(args) cam.open() if not cam.is_opened: sys.exit('Failed to open camera!') trt_ssd = TrtSSD(args.model) cam.start() # initialize bot logger.info('initialize robot') robot = Robot() logger.info('starting to loop and detect') loop_and_detect(cam=cam, trt_ssd=trt_ssd, conf_th=0.3, robot=robot, model=args.model) logger.info('cleaning up') robot.stop() cam.stop() cam.release()
def __init__(self, goal_vel=0.0): self.goal_ticks = self.convert_to_ticks(goal_vel) self.plant = PLANT() self.wheel_controllers = { Sensor.KEY_WENC_RIGHT: Wheel_PID_Controller(True, 0.01), Sensor.KEY_WENC_LEFT: Wheel_PID_Controller(False, 0.01) } self.wheel_inputs = [0.0, 0.0] self.jetbot = Robot()
def __init__(self): self.robot = Robot() #self.robot = JetbotDriver().robot self.left_v = 0.0 self.right_v = 0.0 self.loop = True self.controll_thread = threading.Thread(target=self._controll_loop) rospy.init_node('jetbot_cmd_vel_controller') rospy.Subscriber("/cmd_vel", Twist, self._callback)
def main(): print("import finished.") sleep(2) robot = Robot() r_speed = 0.25 l_speed = 0.25 distance = 50 t1 = threading.Thread(target=drive, \ args=(s1, robot, r_speed, l_speed, distance)) t1.start()
def __init__(self): print("INFO: Starting Formant JetBot Adapter") # Set global params self.max_speed = DEFAULT_MAX_SPEED self.min_speed = DEFAULT_MIN_SPEED self.speed_deadzone = DEFAULT_SPEED_DEADZONE self.speed_increment = DEFAULT_SPEED_INCREMENT self.angular_reduction = DEFAULT_ANGULAR_REDUCTION self.latitude = DEFAULT_LATITUDE self.longitude = DEFAULT_LONGITUDE self.gst_string = DEFAULT_GST_STRING self.start_speed = DEFAULT_START_SPEED self.speed = self.start_speed self.is_shutdown = False # Store frame rate information to publish self.camera_width = 0 self.camera_height = 0 self.camera_frame_timestamps = collections.deque([], maxlen=100) self.camera_frame_sizes = collections.deque([], maxlen=100) # Create clients self.robot = Robot() self.ina219 = INA219(addr=0x41) self.fclient = FormantClient(ignore_throttled=True, ignore_unavailable=True) self.update_from_app_config() self.publish_online_event() self.fclient.register_command_request_callback( self.handle_command_request) self.fclient.register_teleop_callback(self.handle_teleop, ["Joystick", "Buttons"]) print("INFO: Starting speed thread") threading.Thread(target=self.publish_speed, daemon=True).start() print("INFO: Starting motor states thread") threading.Thread(target=self.publish_motor_states, daemon=True).start() print("INFO: Starting location thread") threading.Thread(target=self.publish_location, daemon=True).start() print("INFO: Starting battery state thread") threading.Thread(target=self.publish_battery_state, daemon=True).start() print("INFO: Starting camera stats thread") threading.Thread(target=self.publish_camera_stats, daemon=True).start() # Start the camera feed self.publish_camera_feed()
def main(args=None): rclpy.init(args=args) robot = Robot() motorsNode = MotorsNode(robot) rclpy.spin(motorsNode) sb.destroy_node() rclpy.shutdown()
def __init__(self): super(RobotEnv, self).__init__() #n_actions = 3 n_actions = 2 self.action_space = spaces.Discrete(n_actions) self.observation_space = spaces.Box(0, 255, [224, 224, 3], dtype=np.uint8) self.state = None self.reward = 0 self.speed = 20 self.speed_threshold = 10 self.image = None self.prev_image = None self.robot = Robot()
def __init__(self, port=8765): super().__init__('ws_server') self.cmd_sub_ = self.create_subscription(Twist, 'cmd_vel', self.cmd_callback, 10) self.odom_sub_ = self.create_subscription(Odometry, 'rs_t265/odom', self.odom_callback, 10) self.vel_cmd_ = 0.0 self.yaw_rate_cmd_ = 0.0 self.yaw_rate_error_int_ = 0.0 self.vel_error_int_ = 0.0 if not IS_LOCAL: self.robot = Robot()
def listener(): rospy.init_node('twist_to_motor') rospy.Subscriber('dtw_robot/diff_drive_controller/cmd_vel', Twist, twist_cb) rate = rospy.Rate(10) robot = Robot() global init_flag init_flag = 1 while not rospy.is_shutdown(): robot.set_motors(v_l, v_r) print(v_l) rate.sleep()
def __init__(self): print('Setting up camera') self.camera = Camera.instance(width=224, height=224) print('Set up camera') self.robot = Robot() self.completed = False # Collision Avoidance. print('Loading CA model') self.ca_model = torchvision.models.alexnet(pretrained=False) self.ca_model.classifier[6] = torch.nn.Linear( self.ca_model.classifier[6].in_features, 2) #self.ca_model.load_state_dict(torch.load('best_model_nvidia.pth')) self.device = torch.device('cuda') self.ca_model = self.ca_model.to(self.device) print('Loaded CA model') self.mean = 255.0 * torch.Tensor(np.array([0.485, 0.456, 0.406 ])).cuda().half() self.std = 255.0 * torch.Tensor(np.array([0.485, 0.456, 0.406 ])).cuda().half() self.normalize = torchvision.transforms.Normalize(self.mean, self.std) # Road following support variables. self.angle = 0.0 self.angle_last = 0.0 # Instantiating the road following network. print('Loading RF model') self.rf_model = torchvision.models.resnet18(pretrained=False) self.rf_model.fc = torch.nn.Linear(512, 2) self.rf_model.load_state_dict(torch.load('best_steering_model_xy.pth')) self.rf_model = self.rf_model.to(self.device) self.rf_model = self.rf_model.eval().half() print('Loaded RF Model') # Initializing additional variables. self.speed_gain = 0.12 self.steering_gain = 0 self.steering_dgain = 0.1 self.steering_bias = 0.0 self.starttime = 0 self.cumulative_angle = -1 self.pitstop = [] self.startposition = [] self.start_num = -1 self.baton_callback = None self.pathpoints_callback = None self.pathpoints = [[]] # Add proper value below. self.proportionality_const = -1 self.image_widget = ipywidgets.Image() self.previous_position = -1 traitlets.dlink((self.camera, 'value'), (self.image_widget, 'value'), transform=bgr8_to_jpeg)
async def jsEvent(dev): xAxis = 0 yAxis = 0 speed = 0 torque = 0 midAxis = 128 leftMotorSpeed = 0 rightMotorSpeed = 0 robot = Robot() async for ev in dev.async_read_loop(): if (ev.type == 3): # analog # get the Axis values from the js if (ev.code == 1): # Y axis yAxis = ev.value # maintain state elif (ev.code == 0): # X axis xAxis = ev.value # maintain state for both # Y axis values represent the speed, X the rotation speed = round(scale_js_Y(yAxis),2) torque = round(scale_js_X(xAxis),2) if (speed == 0 and torque == 0): robot.stop() else: # combine speed and torque leftMotorSpeed = speed rightMotorSpeed = speed if (xAxis > midAxis): # rotate right leftMotorSpeed = round((leftMotorSpeed + torque), 2) rightMotorSpeed = round((rightMotorSpeed - torque), 2) else: # rotate left leftMotorSpeed = round((leftMotorSpeed - torque), 2) rightMotorSpeed = round((rightMotorSpeed + torque), 2) if (leftMotorSpeed > 1): leftMotorSpeed = 1 elif (leftMotorSpeed < -1): leftMotorSpeed = -1 elif (rightMotorSpeed > 1): rightMotorSpeed = 1 elif (rightMotorSpeed < -1): rightMotorSpeed = -1 # forward #robot.forward(motorSpeed) #print(repr(ev)) #print(leftMotorSpeed, rightMotorSpeed) print('x-axis', xAxis, 'y-axis', yAxis, 'speed: ',speed, 'torque: ', torque, 'left: ', leftMotorSpeed, 'right: ', rightMotorSpeed)
def main(): # parser = argparse.ArgumentParser(description='PD Control Tester') # parser.add_argument("-p", type=str, help='Port of the serial', required=True) # parser.add_argument("-b", type=int, help="Baudrate of the serial", default=9600) # parser.add_argument("-x", type=float, help="x position of Goal in cm", default=100) # parser.add_argument("-y", type=float, help="y position of Goal in cm", default=0) # parser.add_argument("-theta", type=float, help="theta of Goal", default=0) # args = parser.parse_args() print("import finished.") sleep(2) robot = Robot() l_speed = 1.0 r_speed = 1.0 distance = 100 t1 = threading.Thread(target=drive, \ args=(s1, robot, l_speed, r_speed, distance)) t1.start()
def main(): parser = argparse.ArgumentParser(description='Khan') parser.add_argument("-p", type=str, help='Port of the serial', default='/dev/ttyACM0') parser.add_argument("-b", type=int, help="Baudrate of the serial", default=9600) parser.add_argument("-speed", type=float, help="speed in cm/s", default=10) args = parser.parse_args() # khan = Khan(args.p, args.b) robot = Robot() imageHandler = ImageHandler(width=640, height=480) laneDetector = LaneDetector(imageHandler.camera) print("ready to run, wait for 1 second...") sleep(1) robot.set_motors(0.2,0.3) t1 = threading.Thread(target=markROI(), args=(laneDetector,)) t1.start() sleep(10) robot.stop()
def main(): robot = Robot() pb_file = 'following/faster_rcnn_resnet50_coco_2018_01_28/frozen_inference_graph.pb' cfg_file = 'following/faster_rcnn_resnet50_coco_2018_01_28.pbtxt' cvNet = cv.dnn.readNetFromTensorflow(pb_file, cfg_file) cap = cv.VideoCapture(camSet) try: while cap.isOpened(): ret, frame = cap.read() # sendUDP(frame) img = frame rows = img.shape[0] cols = img.shape[1] cvNet.setInput( cv.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False)) cvOut = cvNet.forward() for detection in cvOut[0, 0, :, :]: score = float(detection[2]) if score > 0.3: print(detection) # Stop the program on the ESC key if cv.waitKey(30) == 27: break except Exception as e: print(e.args[0]) finally: robot.stop() cap.release() sock.close()
def __init__(self): # jetbot setting self.robot = Robot() self.avoidance_status = False self.cruise_status = False self.move_arrow = 'stop' self.n = 0.0 self.direction = "" self.pw = 1 self.pw_c = 1.5 self.left_power = (0.15) self.right_power = (0.145) # deep learning model setting self.set_detect_model() self.set_seg_model() self.roi = [(0, 120),(80, 60),(160, 120),] # camera setting self.cap = cv2.VideoCapture(1) self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) # width self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240) # height self.cap.set(cv2.CAP_PROP_FPS, 10) (self.grabbed, self.frame) = self.cap.read() # thread threading.Thread(target=self.update, args=()).start()
import audioop import wave import tensorflow as tf import time from jetbot import Robot FLAGS = None IN_FILE = 'in.wav' # name of input file CHUNK = 4096 # number of data points to read at a time RATE = 16000 # time resolution of the recording device (Hz) CHANNELS = 1 # number of channels FORMAT = pyaudio.paInt16 # audio format from pyaudio p = pyaudio.PyAudio() # start the PyAudio class devinfo = p.get_device_info_by_index(0) # get the first recorder device robot = Robot() # robot object to control JetBot # choose robot action based on string function_chooser = { 'left': robot.left, 'right': robot.right, 'go': robot.forward, 'down': robot.backward } # stream from pyaudio stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
def __init__(self): self.jetbot = Robot( ) # Robot() is jetbot API for inputting motor controls, no need to manage PWM inputs ourselves.
def main_loop(): global led_power led_power = max_led_power # Get access to the webcam. The method is different depending on if this is running on a laptop or a Jetson Nano. if running_on_jetson_nano(): # Accessing the camera with OpenCV on a Jetson Nano requires gstreamer with a custom gstreamer source string video_capture = cv2.VideoCapture(get_jetson_gstreamer_source(), cv2.CAP_GSTREAMER) else: # Accessing the camera with OpenCV on a laptop just requires passing in the number of the webcam (usually 0) # Note: You can pass in a filename instead if you want to process a video file instead of a live camera stream video_capture = cv2.VideoCapture(0) robot = Robot() print ("beginning Jetbot face recognition loop") noface_count = 0 try: while True: # Grab a single frame of video ret, frame = video_capture.read() # Resize frame of video to 1/4 size for faster face recognition processing small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses) rgb_small_frame = small_frame[:, :, ::-1] # Find all the face locations and face encodings in the current frame of video face_locations = face_recognition.face_locations(rgb_small_frame) #face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) # Grab the image of the the face from the current frame of video if (len(face_locations) > 0): noface_count = 0 max_width = 0 closest_face_left = 0 closest_face_right = 0 for location in face_locations: top, right, bottom, left = location width = right - left if (width > max_width): max_width = width closest_face_left = left closest_face_right = right error = closest_face_left + max_width / 2 - view_position_center if (abs(error) > position_tolerance): if (error > 0): x = threading.Thread(target=swivel_for_time, args=(robot,-swivel_speed,swivel_duration,)) # was robot.left(speed=swivel_speed) else: x = threading.Thread(target=swivel_for_time, args=(robot,swivel_speed,.1,)) # was robot.right(speed=swivel_speed) x.start() #time.sleep(.1) else: robot.stop() with open("/home/jetbot/jethead-stats.txt",'w',encoding = 'utf-8') as f: f.write("{} {} {}".format(closest_face_left, closest_face_right, error)) toggle_green_led(robot) # show heartbeat with red led else: robot.stop() noface_count += 1 with open("/home/jetbot/jethead-stats.txt",'w',encoding = 'utf-8') as f: f.write("{}".format(noface_count)) toggle_red_led(robot) # show heartbeat with red led except: with open("/home/jetbot/jethead-stats.txt",'w',encoding = 'utf-8') as f: f.write("crashed") # Release handle to the webcam print ("cleaning up after jetbot") video_capture.release() cv2.destroyAllWindows()
def __init__(self): self.robot = Robot()
def run(remotecontrol=True, cameracapture=False): global dualshock global robot global axis global continuouscap global continuouscaptime global neuralnet_latched global nnproc prevShutter = False meaningful_input_time = None neuralnet_input_time = None cam_cap_time = None last_speed_debug_time = datetime.datetime.now() last_tick_debug_time = datetime.datetime.now() print("Remote Control script running! ", end=" ") if remotecontrol: print("in RC mode") elif cameracapture: print("in CAMERA mode") else: print("unknown mode, quitting") quit() if remotecontrol: try: robot = Robot() except Exception as ex: sys.stderr.write("Failed to initialize motor drivers, error: %s" % (str(ex))) robot = None while True: dualshock = get_dualshock4() if dualshock != None: print("DualShock4 found, %s" % str(dualshock)) else: time.sleep(2) now = datetime.datetime.now() delta_time = now - last_tick_debug_time if delta_time.total_seconds() > 5: last_tick_debug_time = now sys.stderr.write("tick %s" % (str(now))) while dualshock != None: now = datetime.datetime.now() delta_time = now - last_tick_debug_time if delta_time.total_seconds() > 5: last_tick_debug_time = now sys.stderr.write("tick %s" % (str(now))) try: event = dualshock.read_one() if event != None: gamepad_event_handler(event, is_remotecontrol=remotecontrol, is_cameracapture=cameracapture) else: time.sleep(0) all_btns = dualshock.active_keys() if remotecontrol: meaningful_input = False # meaningful input means any buttons pressed or the stick has been moved if TRIANGLE in all_btns: neuralnet_latched = False mag_dpad, ang_dpad = axis_vector( axis[DPAD_X], axis[DPAD_Y]) mag_left, ang_left = axis_vector( axis_normalize(axis[LEFT_X], curve=0), axis_normalize(axis[LEFT_Y], curve=0)) mag_right, ang_right = axis_vector( axis_normalize(axis[RIGHT_X], curve=0), axis_normalize(axis[RIGHT_Y], curve=0)) now = datetime.datetime.now() if mag_dpad != 0 or mag_left > 0.1 or mag_right > 0.1: meaningful_input = True if meaningful_input_time == None: print("meaningful input!") meaningful_input_time = now elif meaningful_input_time != None: # user may have let go, check for timeout delta_time = now - meaningful_input_time if delta_time.total_seconds() > 2: print( "No meaningful input, stopping robot motors" ) meaningful_input = False meaningful_input_time = None if robot != None: robot.stop() else: meaningful_input = True use_nn = False if SQUARE in all_btns: neuralnet_latched = True if TRIANGLE in all_btns: neuralnet_latched = False if neuralnet_latched or CROSS in all_btns: use_nn = True if meaningful_input == False and nnproc is not None: # remote control inputs always override neural net inputs while sys.stdin in select.select([sys.stdin], [], [], 0)[0]: line = sys.stdin.readline() if line: try: axis[NN_THROTTLE] = int(line[0:3]) axis[NN_STEERING] = int(line[3:]) neuralnet_input_time = now except: pass if neuralnet_input_time != None and use_nn: delta_time = now - neuralnet_input_time if delta_time.total_seconds() < 5: meaningful_input = True meaningful_input_time = now if meaningful_input: left_speed = 0 right_speed = 0 ignore_dpad = False #ignore_rightstick = True if use_nn: start_nn_proc( ) # this will check if process has already started left_speed, right_speed = axis_mix( axis_normalize(axis[NN_STEERING]), axis_normalize(255 - axis[NN_THROTTLE])) elif mag_dpad != 0 and ignore_dpad == False: left_speed, right_speed = axis_mix( float(axis[DPAD_X]) / 3.0, axis[DPAD_Y]) #elif mag_left > mag_right or ignore_rightstick == True: # left_speed, right_speed = axis_mix(axis_normalize(axis[LEFT_X]), axis_normalize(axis[LEFT_Y])) # if ignore_rightstick == False: # left_speed /= 2 # right_speed /= 2 else: # left_speed, right_speed = axis_mix(axis_normalize(axis[RIGHT_X]), axis_normalize(axis[RIGHT_Y])) left_speed, right_speed = axis_mix( axis_normalize(axis[RIGHT_X]), axis_normalize(axis[LEFT_Y])) if robot != None: robot.set_motors(left_speed, right_speed) delta_time = now - last_speed_debug_time if delta_time.total_seconds() >= 1: if use_nn: print("nn -> ", end="") print("leftmotor: %.2f rightmotor: %.2f" % (left_speed, right_speed)) last_speed_debug_time = now elif cameracapture: now = datetime.datetime.now() need_cap = False if L1 in all_btns: if prevShutter == False: if continuouscaptime != None: timedelta = now - continuouscaptime if timedelta.total_seconds() > 0.5: continuouscap = not continuouscap else: continuouscap = not continuouscap prevShutter = True else: prevShutter = False if continuouscap: cam_cap_time = now need_cap = L1 else: if cam_cap_time != None: timedelta = now - cam_cap_time if timedelta.total_seconds() < 1: #need_cap = OTHERCODE pass else: cam_cap_time = None if need_cap != False: snapname = get_snap_name(need_cap) print("saving running pic: " + snapname) cam_capture(snapname) cam_frame_time = now while True: now = datetime.datetime.now() cam_frame_timedelta = now - cam_frame_time if cam_frame_timedelta.total_seconds() >= 0.01: break event = dualshock.read_one() if event != None: gamepad_event_handler( event, is_remotecontrol=False, is_cameracapture=True) except OSError: print("DualShock4 disconnected") dualshock = None if remotecontrol: end_cam_proc() if robot != None: robot.stop()
from jetbot import Robot import xbox import motor import time move = Robot() try: while True: mode = input( "Enter mode: f forward, b backward, l left, r right, s stop, c controller " ) if mode == 'f': move.forward(0.5) print("Jetbot is moving foward!") elif mode == 'b': move.backward(0.5) print("Jetbot is moving backward!") elif mode == 'l': move.left(0.5) print("Jetbot is turning left!") elif mode == 'r': move.right(0.5) print("Jetbot is turning right!") elif mode == 's': move.stop()
def __init__(self): robot = Robot() self.mobile = MobileController(10, robot) #rospy.Subscriber('/joy', Joy, self.joy_stick_callback) rospy.Subscriber("/jetbot/cmd_vel", Twist, self.cmd_vel_callback)
from jetbot import Robot #use jetbot provide function to control the basic movement of the robot import math from time import sleep from helper_function import * from helper_movement import * robot = Robot() #init the class # def object_info(): #maybe able to use machine leaning to learn to turn left or right # #return the distance of the object, the left and right most angle that detect of the object # return 1,2,3 # def turn_no_obj(current_location, target_location, current_angle, target_angle) : # #control the motor # #return the value use to control the motor for calculation # return 1,2 # def turn_obj(distance_to_object, left, right) : # #contorl the motor # #return the value use to control the motor for calculation # return True def simple_PL( x, y, straight_distance, spin_time, turn_time ): #input a coordinate to travel to, +x = go to right, +y = go straight, straight_distance have unit of distance/time, spin_time and turn_time have unit of time to perform a 360 degree turn curr_x = 0 #use to keep track on the x of the car current status curr_y = 0 #use to keep track on the y of the car current status curr_angle = 0 #use to keep track on the angle of the car current status, range from -180 to 180. 0 indicate straight
#For Robot from jetbot import Robot robot = Robot() robotSpeed = 0.4 robot.stop() import jetson.inference import jetson.utils net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5) #camera = jetson.utils.videoSource("csi://0") # '/dev/video0' for V4L2 camera = jetson.utils.videoSource("/dev/video1") # '/dev/video0' for V4L2 display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file #display = jetson.utils.videoOutput("rtp://192.168.1.169:1234") # 'my_video.mp4' for file index = 0 width = 0 location = 0 while display.IsStreaming(): img = camera.Capture() detections = net.Detect(img) display.Render(img) display.SetStatus("Object Detection | Network {:.0f} FPS".format( net.GetNetworkFPS())) for detection in detections: index = detections[0].ClassID width = (detections[0].Width) location = (detections[0].Center[0])
def __init__(self): self.robot = Robot() self.stop()