People
Description
People are considered “actors” in QLabs Open Worlds. The person library controls the people placed in Workspaces in Quanser Interactive Labs.
People actors can be spawned anywhere in the Open Worlds, but to use the move_to methods to allow the people to self-navigate around the environment, they must originate and travel to a connected valid nav area.
For the best visual animation, it is recommended that you use the speed constants defining different gait styles. A character will accurately travel at any specified speed up to 6m/s, but the visual animation may give the impression of “slipping” at certain speeds outside the recommended values.
See the People Tutorial to get a better understanding of using people in Quanser Interactive Labs.
Library
Constants
- QLabsPerson.ID_PERSON = 10030
- QLabsPerson.STANDING = 0
Speed constant for the move_to method.
- QLabsPerson.WALK = 1.2
Speed constant for the move_to method.
- QLabsPerson.JOG = 3.6
Speed constant for the move_to method.
- QLabsPerson.RUN = 6.0
Speed constant for the move_to method.
Member Variables
- QLabsPerson.actorNumber = None
The current actor number of this class to be addressed. This will be set by spawn methods and cleared by destroy methods. It will not be modified by the destroy all actors. This can be manually altered at any time to use one object to address multiple actors.
Methods
- QLabsPerson.enable_collision(enable, waitForConfirmation=True)[source]
Allows for the person to respond and track the number of external collisions. Note that at least one collision filter must also be added.
- Parameters
enable (boolean) – Enable or disable the collision response.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the before proceeding. This makes the method a blocking operation.
- Returns
True if successful, False otherwise.
- Return type
boolean
- QLabsPerson.add_collision_filter(class_id, waitForConfirmation=True)[source]
When collisions are enabled, the person will respond to hits from any actor of this class. This function may be called multiple times to add multiple classes.
- Parameters
class_id – The actor class number to which the person should respond to.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the before proceeding. This makes the method a blocking operation.
- Returns
True if successful, False otherwise.
- Return type
boolean
- QLabsPerson.get_collision_count()[source]
Get the total number of collsions this actor has experienced. Note that collisions must be enabled and at least one collision filter set for this count to be active.
- Returns
status - True if successful or False otherwise
count - Number of hits the person has registered
- Return type
boolean, int32
Parent Class (actor.py) Methods
- QLabsPerson.__init__(qlabs, verbose=False)[source]
Constructor method
- Parameters
qlabs (object) – A QuanserInteractiveLabs object
verbose (boolean) – (Optional) Print error information to the console.
- QLabsPerson.spawn(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor with the next available actor number within this class.
- Parameters
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred. Note that if this is False, the returned actor number will be invalid.
- Returns
status - 0 if successful, 1 class not available, 3 unknown error, -1 communications error.
actorNumber - An actor number to use for future references.
- Return type
int32, int32
Tip
The origin of the person is in the center of the body so by default, it will be spawned 1m above the surface of the target. An additional vertical offset may be required if the surface is sloped to prevent the actor from falling through the world ground surface.
Tip
If you would like to use the move_to method, the actor must be spawned in a valid nav area.
- QLabsPerson.spawn_degrees(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor with the next available actor number within this class.
- Parameters
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in degrees
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred. Note that if this is False, the returned actor number will be invalid.
- Returns
status - 0 if successful, 1 class not available, 3 unknown error, -1 communications error.
actorNumber - An actor number to use for future references.
- Return type
int32, int32
Tip
The origin of the person is in the center of the body so by default, it will be spawned 1m above the surface of the target. An additional vertical offset may be required if the surface is sloped to prevent the actor from falling through the world ground surface.
Tip
If you would like to use the move_to method, the actor must be spawned in a valid nav area.
- QLabsPerson.spawn_id(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 unknown error, -1 communications error
- Return type
int32
Tip
The origin of the person is in the center of the body so by default, it will be spawned 1m above the surface of the target. An additional vertical offset may be required if the surface is sloped to prevent the actor from falling through the world ground surface.
Tip
If you would like to use the move_to method, the actor must be spawned in a valid nav area.
- QLabsPerson.spawn_id_degrees(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 unknown error, -1 communications error
- Return type
int32
Tip
The origin of the person is in the center of the body so by default, it will be spawned 1m above the surface of the target. An additional vertical offset may be required if the surface is sloped to prevent the actor from falling through the world ground surface.
Tip
If you would like to use the move_to method, the actor must be spawned in a valid nav area.
- QLabsPerson.move_to(location, speed, waitForConfirmation=True)
Commands an actor to move from the present location to a new target location by using AI path navigation.
- Parameters
location (float array[3]) – A target destination as an array of floats for x, y and z coordinates in full-scale units.
speed (float) – The speed at which the person should walk to the destination (refer to the constants for recommended speeds)
waitForConfirmation (boolean) – (Optional) Wait for confirmation before proceeding. This makes the method a blocking operation, but only until the command is received. The time for the actor to traverse to the destination is always non-blocking.
- Returns
status - True if successful, False otherwise
- Return type
boolean
Tip
Ensure the start and end locations are in valid navigation areas so the actor can find a path to the destination.
- QLabsPerson.destroy()
Find and destroy a specific actor. This is a blocking operation.
- Returns
numActorsDestroyed - The number of actors destroyed. -1 if failed.
- Return type
int32
- QLabsPerson.destroy_all_actors_of_class()
Find and destroy all actors of this class. This is a blocking operation.
- Returns
numActorsDestroyed - The number of actors destroyed. -1 if failed.
- Return type
int32
- QLabsPerson.ping()
Checks if the actor is still present in the environment. Note that if you did not spawn the actor with one of the spawn functions, you may need to manually set the actorNumber member variable.
- Returns
status - True if successful, False otherwise
- Return type
boolean
- QLabsPerson.get_world_transform()
Get the location, rotation, and scale in world coordinates of the actor.
- Returns
status - True if successful, False otherwise
location
rotation
scale
- Return type
boolean, float array[3], float array[3], float array[3]
- QLabsPerson.get_world_transform_degrees()
Get the location, rotation, and scale in world coordinates of the actor.
- Returns
status - True if successful, False otherwise
location
rotation
scale
- Return type
boolean, float array[3], float array[3], float array[3]
Configurations
There are 12 configurations (0-11) for a person generated in QLabs.
Connection Points
There are no connections points for the person actor.
People Tutorial
Python Tutorial
Raw to download this tutorial: People Tutorial (.py).
1"""
2Person Library Example
3----------------------
4
5.. note::
6
7 Make sure you have Quanser Interactive Labs open before running this
8 example. This example is designed to best be run in QCar Cityscape.
9
10"""
11
12# imports to important libraries
13import sys
14import math
15import time
16
17from qvl.qlabs import QuanserInteractiveLabs
18from qvl.free_camera import QLabsFreeCamera
19from qvl.person import QLabsPerson
20from qvl.system import QLabsSystem
21
22def main():
23
24 # initialize our variables
25 # note that you can use the ..Coordinate Helper to pick locations for your actor.
26 LOCATION_START_P1 = [-6.8, 40.7, 0.005]
27 LOCATION_START_P2 = [-8.5, 40.7, 0.005]
28 LOCATION_START_P3 = [-11.9, 40.7,0.005]
29
30 ROTATION_P1P2 = [0,0,math.pi/2]
31 SCALE = [1,1,1]
32 ROTATION_P3 = [0,0,90]
33
34 LOCATION_END_P1 = [-7.6, 51, 0.005]
35 LOCATION_END_P2 = [-11.0, 48, 0.005]
36 LOCATION_END_P3 = [-23.7, 43, 0.005]
37
38 # creates a server connection with Quanser Interactive Labs and manages the communications
39 qlabs = QuanserInteractiveLabs()
40
41 print("Connecting to QLabs...")
42 if (not qlabs.open("localhost")):
43 print("Unable to connect to QLabs")
44 return
45
46 print("Connected")
47
48 # Use hSystem to set the tutorial title in the upper left of the qlabs window
49 hSystem = QLabsSystem(qlabs)
50 hSystem.set_title_string('People Tutorial')
51
52 # destroy any spawned actors (this is useful if you are running the same script over and over)
53 qlabs.destroy_all_spawned_actors()
54
55 # create a camera in this qlabs instance
56 camera = QLabsFreeCamera(qlabs)
57 # place the custom camera at a specified location and rotation using radians
58 camera.spawn(location=[-2.061, 43.916, 4.348], rotation=[0, 0.383, -3.097])
59 # to switch our view from our current camera to the new camera we just initialized to
60 # be able to view where our people will spawn
61
62 camera.possess()
63
64 # creates an instance of the person
65 person1 = QLabsPerson(qlabs)
66 # place the person at a specified location and rotation using radians
67 # spawn_id allows us to specify the internal number for the actor
68 person1.spawn_id(actorNumber=0, location=LOCATION_START_P1, rotation=ROTATION_P1P2, scale=SCALE, configuration=6, waitForConfirmation=True)
69
70 # creates a second instance of a person
71 person2 = QLabsPerson(qlabs)
72 # place the person at a specified location and rotation using radians
73 # spawn creates the internal number for the actor automatically using
74 # the next available actor number
75 person2.spawn(location=LOCATION_START_P2, rotation=ROTATION_P1P2, scale=SCALE, configuration=7, waitForConfirmation=True)
76
77 # creates a third instance of a person
78 person3 = QLabsPerson(qlabs, True)
79 # place the person at a specified location and rotation using degrees
80 # spawn_degrees creates the internal number for the actor automatically using the next
81 # available number and takes the inputted rotation as degrees
82 person3.spawn_degrees(location=LOCATION_START_P3, rotation=ROTATION_P3, scale=SCALE, configuration=8, waitForConfirmation=True)
83
84 # move the 3 people created to a new location
85 person1.move_to(location=LOCATION_END_P1, speed=person1.WALK, waitForConfirmation=True)
86 person2.move_to(location=LOCATION_END_P2, speed=person2.JOG, waitForConfirmation=True)
87 person3.move_to(location=LOCATION_END_P3, speed=person3.RUN, waitForConfirmation=True)
88
89 time.sleep(3)
90 qlabs.close()
91
92if __name__ == "__main__":
93 main()
Matlab Tutorial
Raw to download this tutorial: People Tutorial (.m).
1% Person Library Example
2% -------------------------
3%
4% .. note::
5%
6% Make sure you have Quanser Interactive Labs open before running this
7% example. This example is designed to best be run in QCar Cityscape.
8
9close all;
10clear all;
11clc;
12
13% --------------------------------------------------------------
14% Setting MATLAB Path for the libraries
15% Always keep at the start, it will make sure it finds the correct references
16newPathEntry = fullfile(getenv('QAL_DIR'), '0_libraries', 'matlab', 'qvl');
17pathCell = regexp(path, pathsep, 'split');
18if ispc % Windows is not case-sensitive
19 onPath = any(strcmpi(newPathEntry, pathCell));
20else
21 onPath = any(strcmp(newPathEntry, pathCell));
22end
23
24if onPath == 0
25 path(path, newPathEntry)
26 savepath
27end
28% --------------------------------------------------------------
29
30if onPath == 0
31 path(path, newPathEntry)
32 savepath
33end
34
35fprintf('\n\n----------------- Communications -------------------\n\n');
36
37qlabs = QuanserInteractiveLabs();
38connection_established = qlabs.open('localhost');
39
40if connection_established == false
41 disp("Failed to open connection.")
42 return
43end
44
45
46disp('Connected')
47
48num_destroyed = qlabs.destroy_all_spawned_actors();
49
50fprintf('%d actors destroyed', num_destroyed);
51
52% Use hSystem to set the tutorial title in the upper left of the qlabs window
53hSystem = QLabsSystem(qlabs);
54hSystem.set_title_string('People Tutorial')
55
56% initialize our variables
57% note that you can use the ..Coordinate Helper to pick locations for your actor.
58LOCATION_START_P1 = [-6.8, 40.7, 0.005];
59ROTATION_P1P2 = [0,0,pi/2];
60SCALE = [1,1,1];
61
62LOCATION_START_P2 = [-8.5, 40.7, 0.005];
63LOCATION_START_P3 = [-11.9, 40.7,0.005];
64ROTATION_P3 = [0,0,90];
65
66LOCATION_END_P1 = [-7.6, 51, 0.005];
67LOCATION_END_P2 = [-11.0, 48, 0.005];
68LOCATION_END_P3 = [-23.7, 43, 0.005];
69
70% create a camera in this qlabs instance
71camera = QLabsFreeCamera(qlabs);
72
73%place the custom camera at a specified location and rotation using radians
74camera.spawn([-2.061, 43.916, 4.348], [0, 0.383, -3.097]);
75
76% to switch our view from our current camera to the new camera we just initialized to
77% be able to view where our people will spawn
78camera.possess();
79
80% creates an instance of the person
81person1 = QLabsPerson(qlabs);
82
83% place the person at a specified location and rotation using radians
84% spawn_id allows us to specify the internal number for the actor
85person1.spawn_id(0, LOCATION_START_P1, ROTATION_P1P2, SCALE, 6, 1);
86
87% creates a second instance of a person
88person2 = QLabsPerson(qlabs);
89
90% place the person at a specified location and rotation using radians
91% spawn creates the internal number for the actor automatically using
92% the next available actor number
93person2.spawn(LOCATION_START_P2, ROTATION_P1P2, SCALE, 7, 1)
94
95% creates a third instance of a person
96person3 = QLabsPerson(qlabs, 1);
97
98% place the person at a specified location and rotation using degrees
99% spawn_degrees creates the internal number for the actor automatically using the next
100% available number and takes the inputted rotation as degrees
101person3.spawn_degrees(LOCATION_START_P3, ROTATION_P3, SCALE, 8, 1);
102
103% move the 3 people created to a new location
104person1.move_to(LOCATION_END_P1, person1.WALK, 1);
105person2.move_to(LOCATION_END_P2, person2.JOG, 1);
106person3.move_to(LOCATION_END_P3, person3.RUN, 1);
107
108pause(3);
109qlabs.close();