Исправлены баги, добавлен код Object.proto, в который будут подставлятяь 3д объекты для последующего спавна
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
controller_manager:
|
||||
ros__parameters:
|
||||
update_rate: 31
|
||||
update_rate: 100
|
||||
|
||||
joint_state_broadcaster:
|
||||
type: "joint_state_broadcaster/JointStateBroadcaster"
|
||||
|
||||
@@ -21,11 +21,7 @@ def _runtime_setup(context, *args, **kwatgs):
|
||||
model_path = LaunchConfiguration("model").perform(context)
|
||||
robot_name = LaunchConfiguration("robot_name").perform(context)
|
||||
world_path = LaunchConfiguration("world").perform(context)
|
||||
rviz_status = LaunchConfiguration("rviz").perform(context).lower() in [
|
||||
"true",
|
||||
"1",
|
||||
"yes",
|
||||
]
|
||||
rviz_status = LaunchConfiguration("rviz").perform(context).lower() in ["true", "1", "yes",]
|
||||
|
||||
transform = LaunchConfiguration("transform").perform(context)
|
||||
rotation = LaunchConfiguration("rotation").perform(context)
|
||||
@@ -40,7 +36,7 @@ def _runtime_setup(context, *args, **kwatgs):
|
||||
executable="robot_state_publisher",
|
||||
name="robot_state_publisher",
|
||||
output="screen",
|
||||
parameters=[{"robot_description": robot_description, "use_sim_time": False}],
|
||||
parameters=[{"robot_description": robot_description, "use_sim_time": True}],
|
||||
)
|
||||
|
||||
webots_launch = IncludeLaunchDescription(
|
||||
|
||||
@@ -35,7 +35,7 @@ def _spawn_setup(context, *args, **kwargs):
|
||||
},
|
||||
LaunchConfiguration("controller").perform(context),
|
||||
],
|
||||
respawn=True,
|
||||
respawn=False,
|
||||
)
|
||||
|
||||
controllers_launch = IncludeLaunchDescription(
|
||||
|
||||
@@ -9,4 +9,4 @@ def load_robot_description(model_path: Path, robot_name: str) -> str:
|
||||
elif suffix == ".urdf":
|
||||
return Path(model_path).read_text(encoding="utf-8")
|
||||
else:
|
||||
raise FileNotFoundError(f"Supported file formats: xacro/urdf")
|
||||
raise FileNotFoundError("Supported file formats: xacro/urdf")
|
||||
@@ -0,0 +1,39 @@
|
||||
#VRML_SIM R2025a utf8
|
||||
# Describe the functionality of your PROTO here.
|
||||
# template language: javascript
|
||||
|
||||
|
||||
PROTO Object [
|
||||
field SFVec3f translation 0 0 0
|
||||
field SFRotation rotation 0 0 1 0
|
||||
field SFString name "my_object"
|
||||
field MFString object_path []
|
||||
field SFNode physics Physics{ }
|
||||
]
|
||||
{
|
||||
Solid {
|
||||
translation IS translation
|
||||
rotation IS rotation
|
||||
name IS name
|
||||
contactMaterial "tool"
|
||||
|
||||
children [
|
||||
Shape {
|
||||
appearance PBRAppearance {
|
||||
roughness 1
|
||||
metalness 0
|
||||
}
|
||||
geometry Mesh {
|
||||
url IS object_path
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
boundingObject Mesh {
|
||||
url IS object_path
|
||||
}
|
||||
|
||||
physics IS physics
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,13 @@ EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2025a/project
|
||||
EXTERNPROTO "https://raw.githubusercontent.com/cyberbotics/webots/R2025a/projects/objects/floors/protos/RectangleArena.proto"
|
||||
EXTERNPROTO "../resource/protos/CollaborativeRobotTable.proto"
|
||||
EXTERNPROTO "../resource/protos/WorkspaceLimiter.proto"
|
||||
EXTERNPROTO "../resource/protos/Object.proto"
|
||||
|
||||
|
||||
WorldInfo {
|
||||
title "iiwa robotics"
|
||||
basicTimeStep 10
|
||||
optimalThreadCount 4
|
||||
contactProperties [
|
||||
ContactProperties {
|
||||
material1 "TableMaterial"
|
||||
@@ -19,11 +23,18 @@ WorldInfo {
|
||||
softERP 1
|
||||
softCFM 0.0001
|
||||
}
|
||||
ContactProperties {
|
||||
material1 "tool"
|
||||
material2 "TableMaterial"
|
||||
bounce 0
|
||||
softCFM 0.002
|
||||
maxContactJoints 100
|
||||
}
|
||||
]
|
||||
}
|
||||
Viewpoint {
|
||||
orientation 0.19675345789351045 -0.08356742903703787 -0.976885132249993 3.928186370440618
|
||||
position 5.324715157515194 -4.7927780008585446 4.166958679133935
|
||||
orientation 0.19663259328507318 -0.09057124279298501 -0.9762850368805829 3.9867817928674034
|
||||
position 5.0239232195737245 -5.039192619765231 4.166958679133935
|
||||
followType "Mounted Shot"
|
||||
ambientOcclusionRadius 3
|
||||
}
|
||||
@@ -34,7 +45,7 @@ TexturedBackgroundLight {
|
||||
luminosity 2
|
||||
}
|
||||
RectangleArena {
|
||||
name "Room"
|
||||
name "Arena"
|
||||
floorSize 12 12
|
||||
wallHeight 2
|
||||
}
|
||||
@@ -43,8 +54,7 @@ CollaborativeRobotTable {
|
||||
locked TRUE
|
||||
showCabinet TRUE
|
||||
}
|
||||
|
||||
Group {
|
||||
DEF limiter Group {
|
||||
children [
|
||||
WorkspaceLimiter {
|
||||
translation -1.56 -0.219999 1.01
|
||||
|
||||
@@ -14,10 +14,16 @@ from webots_ros2_msgs.srv import SpawnNodeFromString
|
||||
class ObjectSpawner(Node):
|
||||
def __init__(self):
|
||||
super().__init__("object_spawner")
|
||||
|
||||
# параметры передаваемые
|
||||
self.declare_parameter('objects_path', '')
|
||||
|
||||
# переменные
|
||||
self._object_count: int = randint(1, 5)
|
||||
self._spawned_count: int = 0
|
||||
self._call_in_progress: bool = False
|
||||
|
||||
# Реализация
|
||||
self.cli = self.create_client(
|
||||
SpawnNodeFromString, "/Ros2Supervisor/spawn_node_from_string"
|
||||
)
|
||||
@@ -29,7 +35,9 @@ class ObjectSpawner(Node):
|
||||
|
||||
self._timer = self.create_timer(0.1, self.timer_callback)
|
||||
|
||||
# TODO: переделать процесс спавна, должен сформировать все proto файлы, после чего заспавнить все объекты
|
||||
def timer_callback(self):
|
||||
# TODO: здесь должен получать объекты
|
||||
if self._spawned_count >= self._object_count:
|
||||
self.get_logger().info(f"All {self._object_count} objects spawned")
|
||||
self._timer.cancel()
|
||||
@@ -39,6 +47,7 @@ class ObjectSpawner(Node):
|
||||
return
|
||||
|
||||
data = 'Solid { name "test_box2" translation 0 1 0.5 children [ Shape { appearance PBRAppearance { baseColor 0.901961 0.380392 0 } geometry Box { size 0.1 0.1 0.1 } } ] boundingObject Box { size 0.1 0.1 0.1 } physics Physics { } }'
|
||||
data = self._create_group(children=[data])
|
||||
|
||||
req = SpawnNodeFromString.Request(data=data, check_fields=True)
|
||||
self.get_logger().info(
|
||||
@@ -58,6 +67,10 @@ class ObjectSpawner(Node):
|
||||
self._call_in_progress = False
|
||||
self._spawned_count += 1
|
||||
|
||||
# Вспомогательные методы формирования кода для спавна объектов
|
||||
def _create_group(self, children: list[str]) -> str:
|
||||
return f"DEF OBJECTS Group {{children [{" ".join(children)}]}}"
|
||||
|
||||
|
||||
def main(args=None):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user