Conveyors
Description
Conveyors are considered an “actor” in Quanser Interactive Labs Open Worlds. The conveyor library controls the conveyors available to be placed in the QLabs environment. Conveyors can be straight or curved and can be spawned anywhere in the Open Worlds.
See the Conveyors Tutorial to get a better understanding of using conveyors in Quanser Interactive Labs.
Table of Contents
Important
All of the office objects have the same methods and member variables. To simplify this documentation, the methods and member variables are documented only once, see Shared Variables and Methods and the Conveyors Tutorial. No office object has connection points or different configurations.
Straight Conveyor
Library
Constants
- QLabsConveyorStraight.ID_CONVEYOR_STRAIGHT = 210
Configurations
A spawned straight conveyor with configuration set to 0 will create a conveyor of 0.5 m in length. For each number you increase the configuration the length will increase by .25m. For example, a configuration of 3 will create a 1.25m conveyor. The configuration number accepts whole number between 0 and 20.
All types of conveyors can be connected to make a setup of your choosing.
Curved Conveyor
Library
Constants
- QLabsConveyorCurved.ID_CONVEYOR_CURVED = 211
Configurations
By default, the curved conveyor is spawned from the center and has a radius of 0.5m. When configuration is set to 1, it will create a 15 degree conveyor. For each number you increase the configuration the length will increase by 15 degrees.
For example, a configuration of 3 will create a 45 degree conveyor. The configuration number accepts whole numbers between 1 and 24.
Using a configuration number of 24 will create a circular conveyor.
All types of conveyors can be connected to make a setup of your choosing.
Conveyors Tutorial
Python Tutorial
Raw to download this tutorial: Conveyor Tutorial (.py).
1"""
2Conveyor 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 any of the open
9 world environments.
10
11"""
12
13# imports to important libraries
14import sys
15import math
16import time
17
18from qvl.qlabs import QuanserInteractiveLabs
19from qvl.free_camera import QLabsFreeCamera
20from qvl.system import QLabsSystem
21from qvl.widget import QLabsWidget
22from qvl.conveyor_curved import QLabsConveyorCurved
23from qvl.conveyor_straight import QLabsConveyorStraight
24
25def main():
26
27 # creates a server connection with Quanser Interactive Labs and manages the communications
28 qlabs = QuanserInteractiveLabs()
29
30 print("Connecting to QLabs...")
31 if (not qlabs.open("localhost")):
32 print("Unable to connect to QLabs")
33 return
34
35 print("Connected")
36
37 # Use hSystem to set the tutorial title in the upper left of the qlabs window
38 hSystem = QLabsSystem(qlabs)
39 hSystem.set_title_string('Conveyor Tutorial')
40
41 # destroy any spawned actors (this is useful if you are running the same script over and over)
42 qlabs.destroy_all_spawned_actors()
43
44
45
46 cylinder = QLabsWidget(qlabs)
47 # create a camera in this qlabs instance
48 camera = QLabsFreeCamera(qlabs)
49 # place the custom camera at a specified location and rotation using radians
50 camera.spawn(location=[0.8, 0.7, 1.3], rotation=[0, 0.8, -1.581])
51 # to switch our view from our current camera to the new camera we just initialized to
52 # be able to view where our people will spawn
53 camera.possess()
54
55 ### Create conveyors
56 # The configuration argument is an integer associated with the length of the conveyors
57 # For straight conveyor, configuration = 0 corresponds to a length of 0.5. With each
58 # increase in configuration, the length is increased by 0.25, up to configuration = 20
59 straightConveyor = QLabsConveyorStraight(qlabs)
60 straightConveyor.spawn_id_degrees(actorNumber = 0,
61 location = [0, 0, 0],
62 rotation = [0, 0, 0],
63 scale = [1,1,1],
64 configuration = 5)
65 # For curved conveyor, configuration = 0 corresponds to a circular arc of 15 degree.
66 # With each increase in configuration, the arc length is increased by 15 degrees, up to
67 # configuration = 24.
68 curvedConveyor = QLabsConveyorCurved(qlabs)
69 curvedConveyor.spawn_id_degrees(actorNumber = 1,
70 location = [0.03, -0.5, 0],
71 rotation = [0, 0, 0],
72 scale = [1,1,1],
73 configuration = 6)
74 time.sleep(2)
75
76 ### set the speed for each conveyor
77 straightConveyor.set_speed(0.3)
78 curvedConveyor.set_speed(0.07)
79
80 time.sleep(2)
81
82 ### drop one cylinder widget on top of the straight conveyor
83 cylinder.spawn(location = [1.6, 0, 1],
84 rotation = [0, 0, .5],
85 scale = [.05, .05, .05],
86 configuration = cylinder.CYLINDER)
87
88 time.sleep(1)
89
90 qlabs.close()
91
92if __name__ == "__main__":
93 main()
Matlab Tutorial
Raw to download this tutorial: Conveyor Tutorial (.m).
1% Conveyor 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 any of the open
8% world environments.
9
10close all;
11clear all;
12clc;
13
14% --------------------------------------------------------------
15% Setting MATLAB Path for the libraries
16% Always keep at the start, it will make sure it finds the correct references
17newPathEntry = fullfile(getenv('QAL_DIR'), '0_libraries', 'matlab', 'qvl');
18pathCell = regexp(path, pathsep, 'split');
19if ispc % Windows is not case-sensitive
20 onPath = any(strcmpi(newPathEntry, pathCell));
21else
22 onPath = any(strcmp(newPathEntry, pathCell));
23end
24
25if onPath == 0
26 path(path, newPathEntry)
27 savepath
28end
29% --------------------------------------------------------------
30
31fprintf('\n\n----------------- Communications -------------------\n\n');
32
33qlabs = QuanserInteractiveLabs();
34connection_established = qlabs.open('localhost');
35
36if connection_established == false
37 disp("Failed to open connection.")
38 return
39end
40
41
42disp('Connected')
43
44num_destroyed = qlabs.destroy_all_spawned_actors();
45
46fprintf('%d actors destroyed', num_destroyed);
47
48% Use hSystem to set the tutorial title in the upper left of the qlabs window
49hSystem = QLabsSystem(qlabs);
50hSystem.set_title_string('Conveyor Tutorial')
51
52cylinder = QLabsWidget(qlabs);
53
54% create a camera in this qlabs instance
55camera = QLabsFreeCamera(qlabs);
56
57% place the custom camera at a specified location and rotation using radians
58camera.spawn([0.8,0.7,1.3],[0,0.8,-1.581]);
59
60% to switch our view from our current camera to the new camera we just initialized to
61% be able to view where our people will spawn
62camera.possess();
63
64% The configuration argument is an integer associated with the length of the conveyors
65% For straight conveyor, configuration = 0 corresponds to a length of 0.5. With each
66% increase in configuration, the length is increased by 0.25, up to configuration = 20
67straightConveyor = QLabsConveyorStraight(qlabs);
68straightConveyor.spawn_id_degrees(0,[0, 0, 0], [0, 0, 0], [1,1,1], 5);
69
70% For curved conveyor, configuration = 0 corresponds to a circular arc of 15 degree.
71% With each increase in configuration, the arc length is increased by 15 degrees, up to
72% configuration = 24.
73curvedConveyor = QLabsConveyorCurved(qlabs);
74curvedConveyor.spawn_id_degrees(1,[0.03, -0.5, 0], [0, 0, 0], [1,1,1], 6);
75
76pause(2);
77
78% set the speed for each conveyor
79straightConveyor.set_speed(0.3);
80curvedConveyor.set_speed(0.07);
81
82% drop one cylinder widget on top of the straight conveyor
83cylinder.spawn([1.6, 0, 1], [0, 0, 5], [0.05, 0.05, 0.05], cylinder.CYLINDER)
84
85pause(1);
86
87qlabs.close()