Statistics: Posted by Alan — Tue Dec 16, 2014 9:17 pm
#! /usr/bin/python
# This example shows how to use the websockets interface to make the robot move around
import time
import argparse
import cv2
import py_websockets_bot
max_up_degrees = 30.0
max_down_degrees = 150.0
hor_degrees = 140.0
step = 1.0
pan_max = 180.0
pan_start = 10.0
pan_end = 170.0
latest_small_camera_image = None
#---------------------------------------------------------------------------------------------------
def camera_small_image_callback( image, image_time ):
global latest_small_camera_image
# Put image processing here...
latest_small_camera_image = image
#---------------------------------------------------------------------------------------------------
if __name__ == "__main__":
# Set up a parser for command line arguments
parser = argparse.ArgumentParser( "Moves the robot around" )
parser.add_argument( "hostname", default="localhost", nargs='?', help="The ip address of the robot" )
args = parser.parse_args()
# Connect to the robot
bot = py_websockets_bot.WebsocketsBot( args.hostname )
#center neck
bot.centre_neck()
time.sleep( 1.0 )
# Look horizontal
bot.set_neck_angles( pan_angle_degrees=90.0, tilt_angle_degrees=hor_degrees )
time.sleep( 0.1 )
# Start streaming images from the camera
bot.start_streaming_small_camera_images( camera_small_image_callback )
time.sleep ( 1.0 )
# scan left to right
try:
for i in range(10, 170, 1):
bot.set_neck_angles( pan_angle_degrees = i, tilt_angle_degrees=hor_degrees )
bot.update()
time.sleep( 0.5 )
print i
if latest_small_camera_image != None:
cv2.imshow( "small_image", latest_small_camera_image )
cv2.waitKey( 1 )
except KeyboardInterrupt:
pass # Catch Ctrl+C
#center neck
bot.centre_neck()
time.sleep( 1.0 )
# Stop
bot.set_motor_speeds( 0.0, 0.0 )
time.sleep( 0.75 )
# Disconnect from the robot
bot.disconnect()
Statistics: Posted by DannyM — Sun Dec 14, 2014 2:12 pm
Statistics: Posted by DannyM — Sun Dec 14, 2014 12:49 pm