Page 1 of 1

Speed of neck

PostPosted: Sun Dec 14, 2014 12:49 pm
by DannyM
Hi all,

Is it possible to set the speed of the neck, like done in the speed of the wheels.
With motor_test.py the neck is rapidly changed.

Danny

Re: Speed of neck

PostPosted: Sun Dec 14, 2014 2:12 pm
by DannyM
Hi,

I have found a sollution for the quick movement of the camera.
Now the camera pans a 160degrees and shows a picture.

Can you please tell me where the cv2.waitKey( 1 ) in line 61, is for?

Next step is to stop the camera when it finds a ball...

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 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()

Re: Speed of neck

PostPosted: Tue Dec 16, 2014 9:17 pm
by Alan
Hi Danny,

Sorry for the delayed reply. Had a git of a head cold over the last couple of days. :(

The cv2.waitKey( 1 ) line is needed to make the OpenCV debug windows appear. Basically if you don't have any calls to cv2.imshow then you don't need to call waitKey. The number is the time to wait in milliseconds for a keypress. If you use 0 then the program will pause.

Regards

Alan