Conveyor Model
In this example, you will define a conveyor simulation model and a simulation with a box on it, see Fig. 10.
Run the Simulation
Open a terminal in VS Code and start the conveyor.py Python script with the following command:
python models/conveyor/conveyor.py
Open localhost:8077 in your web browser to display the simulation as shown in Fig. 10. After the conveyor belt and the box have been loaded, the Python script waits until you press the Enter key. After you have pressed the Enter key, the conveyor belt starts with a positive velocity. The box moves accordingly the conveyor belt stops as shown in Fig. 11.
Fig. 11 The conveyor belt with box moving in positive x direction
After the box has moved, the simulation pauses and waits until you have pressed the Enter key again. Press the Enter key to stop the conveyor belt and continue the simulation. The box will stop as shown in Fig. 12.
The script pauses again and waits until you have pressed the Enter key. Press the Enter key to start the conveyor belt with negative velocity and run the simulation to the end. The box will move in opposite direction as shown in Fig. 13.
Fig. 13 The conveyor belt with box moving in negative x direction
The Conveyor Python File
The Python file models/conveyor/conveyor.py defines the conveyor simulation model.
The conveyor simulation is done by applying a linear velocity to the physics model.
This exerts a force on all dynamic objects lying on the conveyor belt,
taking friction into account.
After the simulation step has been calculated,
the position of the conveyor belt physics model is reset without taking the physics into account.
1"""Contains a conveyor simulation model."""
2
3from pathlib import Path
4
5from voraus_3d_visu import Visu
6
7from voraus_simulation import DynamicObject
8
9models = Path(__file__).parent
10
11
12class Conveyor(DynamicObject):
13 """Describes a conveyor simulation model."""
14
15 def __init__(self, position: list[float], rotation: list[float], velocity: float) -> None:
16 """Initializes a conveyor simulation model.
17
18 Args:
19 position: The initial position.
20 rotation: The initial rotation.
21 velocity: The default velocity.
22 """
23 glb_path = models / "conveyor.glb"
24 urdf_path = models / "conveyor.urdf"
25 super().__init__(glb_path, urdf_path, position, rotation)
26
27 self.velocity = velocity
28
29 def update(self, enable: bool, velocity: float | None = None) -> None:
30 """Updates the state of the conveyor.
31
32 Args:
33 enable: True if conveyor is enabled, else false.
34 velocity: The velocity in m/s, uses default velocity if None. Defaults to None.
35 """
36 velocity = self.velocity if velocity is None else velocity
37 if enable:
38 self.set_velocity(linear_velocity=[velocity, 0, 0], use_local=True)
39 else:
40 self.set_velocity(linear_velocity=[0, 0, 0])
41
42 def get_visu_data(self) -> list:
43 """Do not update conveyor position of visual model."""
44 return []
45
46
47if __name__ == "__main__":
48 import sys
49
50 sys.path.append(str(Path(__file__).parent.parent.parent))
51
52 from models.box.box import Box
53
54 from voraus_simulation import Simulation
55
56 simulation = Simulation(frequency=50, visualization=Visu("http://voraus-3d-visu/"))
57
58 with simulation.run():
59 conveyor = Conveyor([0.95, 0.7, 0], rotation=[0, 0, 0], velocity=0.5)
60 box = Box([0.1, 0.7, 0.43])
61
62 frame = 0
63 while True:
64 if frame == 100:
65 input("Press <enter> to start the conveyor.")
66 elif 100 <= frame < 200:
67 conveyor.update(True, velocity=+0.5)
68 if frame == 200:
69 input("Press <enter> to stop the conveyor.")
70 elif 200 < frame < 250:
71 conveyor.update(False)
72 elif frame == 250:
73 input("Press <enter> to start the conveyor in opposite direction.")
74 elif 250 < frame < 300:
75 conveyor.update(True, velocity=-1.0)
76 elif frame > 350:
77 break
78
79 simulation.step()
80 conveyor.reset_pose()
81 simulation.sleep()
82 frame += 1
The Conveyor URDF File
The URDF file models/conveyor/conveyor.urdf defines the conveyor simulation parameters.
1<?xml version="1.0" ?>
2<robot name="box">
3 <link name="baseLink">
4 <contact>
5 <lateral_friction value="1.0"/>
6 <rolling_friction value="0.0"/>
7 <contact_cfm value="0.0"/>
8 <contact_erp value="1.0"/>
9 </contact>
10 <inertial>
11 <origin rpy="0 0 0" xyz="0 0 0"/>
12 <mass value="0"/>
13 <inertia ixx="1" ixy="0" ixz="0" iyy="1" iyz="0" izz="1"/>
14 </inertial>
15 <visual>
16 <origin rpy="0 0 0" xyz="0 0 0"/>
17 <geometry>
18 <mesh filename="conveyor.obj" scale="1 1 1"/>
19 </geometry>
20 <material name="white">
21 <color rgba="1 1 1 1"/>
22 </material>
23 </visual>
24 <collision>
25 <origin rpy="0 0 0" xyz="0 0 0"/>
26 <geometry>
27 <mesh filename="conveyor.obj" scale="1 1 1"/>
28 </geometry>
29 </collision>
30 </link>
31</robot>