I have build the Pi Camera Robot and connected it to my LAN. With help of the blog I've installed OpenCV, Numby and Python on my windows7 computer.
I ran the examples, and they worked.
Now I have tried to write my first py script.
I tried to let the camera take pictures of 0 to 180 degrees pan in steps of 10deg, but there is a unsupported array type, what is wrong?
Danny
- Code: Select all
#! /usr/bin/python
# This example shows how to use the websockets interface to make the robot move around
import time
import argparse
import py_websockets_bot
import cv2
latest_small_camera_image = None
i = 0
#---------------------------------------------------------------------------------------------------
def camera_small_image_callback( image, image_time ):
global latest_small_camera_image
# Put image processing here...
latest_small_camera_image = image
#---------------------------------------------------------------------------------------------------
def change_angle ( angle, angle_time ):
# global angle
bot.set_neck_angles( pan_angle_degrees=angle, tilt_angle_degrees=90.0 )
cv2.imshow( "image", latest_small_camera_image )
time.sleep( angle_time )
#---------------------------------------------------------------------------------------------------
if __name__ == "__main__":
# Set up a parser for command line arguments
parser = argparse.ArgumentParser( "Moves the robot around" )
parser.add_argument( "hostname", default="192.168.1.38", nargs='?', help="The ip address of the robot" )
args = parser.parse_args()
# Connect to the robot
bot = py_websockets_bot.WebsocketsBot( args.hostname )
# Drive forwards
bot.set_motor_speeds( 15.0, 15.0 )
time.sleep( 1.0 )
# Stop
bot.set_motor_speeds( 0.0, 0.0 )
time.sleep( 0.75 )
# Turn left
bot.set_motor_speeds( -15.0, 0.0 )
time.sleep( 1.25 )
# Stop
bot.set_motor_speeds( 0.0, 0.0 )
time.sleep( 0.75 )
# Drive forwards
bot.set_motor_speeds( 15.0, 15.0 )
time.sleep( 1.0 )
# Stop
bot.set_motor_speeds( 0.0, 0.0 )
time.sleep( 0.75 )
# Stop
bot.set_motor_speeds( 0.0, 0.0 )
time.sleep( 0.75 )
# Start streaming images from the camera
bot.start_streaming_small_camera_images( camera_small_image_callback )
# Run in a loop until i is 180deg
try:
for i in range( 10, 180, 10 ):
bot.update()
# if latest_small_camera_image != None:
#change_angle ( i, 1.0 )
cv2.imshow( "small_image", latest_small_camera_image )
cv2.waitKey( 1 )
except KeyboardInterrupt:
pass # Catch Ctrl+C
# Look right
# bot.set_neck_angles( pan_angle_degrees=180.0, tilt_angle_degrees=90.0 )
# time.sleep( 2.0 )
# Centre the neck
bot.centre_neck()
time.sleep( 1.0 )
# Disconnect from the robot
bot.disconnect()
# Look left
# bot.set_neck_angles( pan_angle_degrees=0.0, tilt_angle_degrees=90.0 )
# time.sleep( 2.0 )
# Start streaming images from the camera
# bot.start_streaming_camera_images( camera_image_callback )
# bot.start_streaming_small_camera_images( camera_small_image_callback )
# Run in a loop until the user presses Ctrl+C to quit
# try:
# while True:
# bot.update()
# if latest_camera_image != None:
# cv2.imshow( "image", latest_camera_image )
# if latest_small_camera_image != None:
# cv2.imshow( "small_image", latest_small_camera_image )
# cv2.waitKey( 1 )
# except KeyboardInterrupt:
# pass # Catch Ctrl+C
# Disconnect from the robot
# bot.disconnect()