There are three different modes that you can use in this Python code (Misty's head will always move):
Mode 1: No driving ("turnInPlace" : false, "followHuman" : false)
Mode 2: Allow turning in place, but not driving forward/backward ("turnInPlace" : true, "followHuman" : false)
Mode 3: Allow full driving ("turnInPlace" : true, "followHuman" : true)
Constants
Those constants are used to calibrate the maximum range of movement of Misty's head.
Those should be equal for all Misty's but it would be preferred to check them before you run your code to have better accuracy.
To do it you can use this code:
from mistyPy.Robot import Robotfrom mistyPy.Events import Eventsimport timemisty =Robot("YOUR_ROBOT_IP_ADDRESS")misty.change_led(0, 255, 0)misty.move_head(0, 0, 0)#constantsyaw_left =0yaw_right =0pitch_up =0pitch_down =0print(------)#get current position functionsdefcurr_position(data):global ------ if data["message"]["sensorId"] =="ahp": ------ = data["message"]["value"] time.sleep(0.5)print(------)defget_pos(): misty.move_head(90, 0, 0) time.sleep(5) misty.register_event(event_name="get_curr_position", event_type= Events.ActuatorPosition, keep_alive= True, callback_function=curr_position)
time.sleep(0.25) misty.unregister_event(event_name="get_curr_position")get_pos()
Replace in the marked space (------) the name of the position that you want to check and adjust the move_head parameters and the type of data according to the following table
For example, if you want to check the position of the yaw left your code should look like this one:
from mistyPy.Robot import Robotfrom mistyPy.Events import Eventsimport timemisty =Robot("YOUR_ROBOT_IP_ADDRESS")misty.change_led(0, 255, 0)misty.move_head(0, 0, 0)#constantsyaw_left =0yaw_right =0pitch_up =0pitch_down =0print(yaw_left)#get current position functionsdefcurr_position(data):global yaw_left if data["message"]["sensorId"] =="ahy": yaw_left = data["message"]["value"] time.sleep(0.5)print(yaw_left)defget_pos(): misty.move_head(0, 0, 90) time.sleep(5)#give Misty enough time to achieve the position misty.register_event(event_name="get_curr_position", event_type= Events.ActuatorPosition, keep_alive= True, callback_function=curr_position)
time.sleep(0.25) misty.unregister_event(event_name="get_curr_position")get_pos()
Then you can replace this number in the constants of the main code.
The variables will contain Misty's current head position and the following functions are used:
Record the position and get it as a number memorized in the variables and follow the human.
Detect and follow the person.
The math in the code is to better handle the person's position and adapt Misty's movements.