Исправлены баги, добавлен код Object.proto, в который будут подставлятяь 3д объекты для последующего спавна
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
sudo apt install -y ros-${ROS_DISTRO}-webots-ros2 \
|
sudo apt install -y ros-${ROS_DISTRO}-webots-ros2 \
|
||||||
ros-${ROS_DISTRO}-ros2-control \
|
ros-${ROS_DISTRO}-ros2-control \
|
||||||
ros-${ROS_DISTRO}-ros2-controllers \
|
ros-${ROS_DISTRO}-ros2-controllers \
|
||||||
ros-${ROS_DISTRO}-moveit-* \
|
ros-${ROS_DISTRO}-moveit \
|
||||||
```
|
```
|
||||||
|
|
||||||
Установка moveit2 (внимательно проверяй)
|
Установка moveit2 (внимательно проверяй)
|
||||||
@@ -23,12 +23,7 @@ sudo apt install -y build-essential \
|
|||||||
wget
|
wget
|
||||||
|
|
||||||
# Not Using
|
# Not Using
|
||||||
git clone https://github.com/moveit/moveit2.git
|
LC_ALL=C ros2 launch iiwa_moveit demo...
|
||||||
vcs import --recursive < moveit2/moveit2.repos
|
|
||||||
sudo apt remove ros-$ROS_DISTRO-moveit*
|
|
||||||
rosdep install -r --from-paths ./src/ --ignore-src --rosdistro $ROS_DISTRO --os=ubuntu:noble -y
|
|
||||||
|
|
||||||
colcon build --mixin release
|
|
||||||
|
|
||||||
sudo pip3 install transforms3d --break-system-packages
|
sudo pip3 install transforms3d --break-system-packages
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
controller_manager:
|
controller_manager:
|
||||||
ros__parameters:
|
ros__parameters:
|
||||||
update_rate: 31
|
update_rate: 100
|
||||||
|
|
||||||
joint_state_broadcaster:
|
joint_state_broadcaster:
|
||||||
type: "joint_state_broadcaster/JointStateBroadcaster"
|
type: "joint_state_broadcaster/JointStateBroadcaster"
|
||||||
|
|||||||
@@ -21,11 +21,7 @@ def _runtime_setup(context, *args, **kwatgs):
|
|||||||
model_path = LaunchConfiguration("model").perform(context)
|
model_path = LaunchConfiguration("model").perform(context)
|
||||||
robot_name = LaunchConfiguration("robot_name").perform(context)
|
robot_name = LaunchConfiguration("robot_name").perform(context)
|
||||||
world_path = LaunchConfiguration("world").perform(context)
|
world_path = LaunchConfiguration("world").perform(context)
|
||||||
rviz_status = LaunchConfiguration("rviz").perform(context).lower() in [
|
rviz_status = LaunchConfiguration("rviz").perform(context).lower() in ["true", "1", "yes",]
|
||||||
"true",
|
|
||||||
"1",
|
|
||||||
"yes",
|
|
||||||
]
|
|
||||||
|
|
||||||
transform = LaunchConfiguration("transform").perform(context)
|
transform = LaunchConfiguration("transform").perform(context)
|
||||||
rotation = LaunchConfiguration("rotation").perform(context)
|
rotation = LaunchConfiguration("rotation").perform(context)
|
||||||
@@ -40,7 +36,7 @@ def _runtime_setup(context, *args, **kwatgs):
|
|||||||
executable="robot_state_publisher",
|
executable="robot_state_publisher",
|
||||||
name="robot_state_publisher",
|
name="robot_state_publisher",
|
||||||
output="screen",
|
output="screen",
|
||||||
parameters=[{"robot_description": robot_description, "use_sim_time": False}],
|
parameters=[{"robot_description": robot_description, "use_sim_time": True}],
|
||||||
)
|
)
|
||||||
|
|
||||||
webots_launch = IncludeLaunchDescription(
|
webots_launch = IncludeLaunchDescription(
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def _spawn_setup(context, *args, **kwargs):
|
|||||||
},
|
},
|
||||||
LaunchConfiguration("controller").perform(context),
|
LaunchConfiguration("controller").perform(context),
|
||||||
],
|
],
|
||||||
respawn=True,
|
respawn=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
controllers_launch = IncludeLaunchDescription(
|
controllers_launch = IncludeLaunchDescription(
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ def load_robot_description(model_path: Path, robot_name: str) -> str:
|
|||||||
elif suffix == ".urdf":
|
elif suffix == ".urdf":
|
||||||
return Path(model_path).read_text(encoding="utf-8")
|
return Path(model_path).read_text(encoding="utf-8")
|
||||||
else:
|
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 "https://raw.githubusercontent.com/cyberbotics/webots/R2025a/projects/objects/floors/protos/RectangleArena.proto"
|
||||||
EXTERNPROTO "../resource/protos/CollaborativeRobotTable.proto"
|
EXTERNPROTO "../resource/protos/CollaborativeRobotTable.proto"
|
||||||
EXTERNPROTO "../resource/protos/WorkspaceLimiter.proto"
|
EXTERNPROTO "../resource/protos/WorkspaceLimiter.proto"
|
||||||
|
EXTERNPROTO "../resource/protos/Object.proto"
|
||||||
|
|
||||||
|
|
||||||
WorldInfo {
|
WorldInfo {
|
||||||
title "iiwa robotics"
|
title "iiwa robotics"
|
||||||
|
basicTimeStep 10
|
||||||
|
optimalThreadCount 4
|
||||||
contactProperties [
|
contactProperties [
|
||||||
ContactProperties {
|
ContactProperties {
|
||||||
material1 "TableMaterial"
|
material1 "TableMaterial"
|
||||||
@@ -19,11 +23,18 @@ WorldInfo {
|
|||||||
softERP 1
|
softERP 1
|
||||||
softCFM 0.0001
|
softCFM 0.0001
|
||||||
}
|
}
|
||||||
|
ContactProperties {
|
||||||
|
material1 "tool"
|
||||||
|
material2 "TableMaterial"
|
||||||
|
bounce 0
|
||||||
|
softCFM 0.002
|
||||||
|
maxContactJoints 100
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Viewpoint {
|
Viewpoint {
|
||||||
orientation 0.19675345789351045 -0.08356742903703787 -0.976885132249993 3.928186370440618
|
orientation 0.19663259328507318 -0.09057124279298501 -0.9762850368805829 3.9867817928674034
|
||||||
position 5.324715157515194 -4.7927780008585446 4.166958679133935
|
position 5.0239232195737245 -5.039192619765231 4.166958679133935
|
||||||
followType "Mounted Shot"
|
followType "Mounted Shot"
|
||||||
ambientOcclusionRadius 3
|
ambientOcclusionRadius 3
|
||||||
}
|
}
|
||||||
@@ -34,7 +45,7 @@ TexturedBackgroundLight {
|
|||||||
luminosity 2
|
luminosity 2
|
||||||
}
|
}
|
||||||
RectangleArena {
|
RectangleArena {
|
||||||
name "Room"
|
name "Arena"
|
||||||
floorSize 12 12
|
floorSize 12 12
|
||||||
wallHeight 2
|
wallHeight 2
|
||||||
}
|
}
|
||||||
@@ -43,8 +54,7 @@ CollaborativeRobotTable {
|
|||||||
locked TRUE
|
locked TRUE
|
||||||
showCabinet TRUE
|
showCabinet TRUE
|
||||||
}
|
}
|
||||||
|
DEF limiter Group {
|
||||||
Group {
|
|
||||||
children [
|
children [
|
||||||
WorkspaceLimiter {
|
WorkspaceLimiter {
|
||||||
translation -1.56 -0.219999 1.01
|
translation -1.56 -0.219999 1.01
|
||||||
|
|||||||
@@ -14,10 +14,16 @@ from webots_ros2_msgs.srv import SpawnNodeFromString
|
|||||||
class ObjectSpawner(Node):
|
class ObjectSpawner(Node):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("object_spawner")
|
super().__init__("object_spawner")
|
||||||
|
|
||||||
|
# параметры передаваемые
|
||||||
|
self.declare_parameter('objects_path', '')
|
||||||
|
|
||||||
|
# переменные
|
||||||
self._object_count: int = randint(1, 5)
|
self._object_count: int = randint(1, 5)
|
||||||
self._spawned_count: int = 0
|
self._spawned_count: int = 0
|
||||||
self._call_in_progress: bool = False
|
self._call_in_progress: bool = False
|
||||||
|
|
||||||
|
# Реализация
|
||||||
self.cli = self.create_client(
|
self.cli = self.create_client(
|
||||||
SpawnNodeFromString, "/Ros2Supervisor/spawn_node_from_string"
|
SpawnNodeFromString, "/Ros2Supervisor/spawn_node_from_string"
|
||||||
)
|
)
|
||||||
@@ -29,7 +35,9 @@ class ObjectSpawner(Node):
|
|||||||
|
|
||||||
self._timer = self.create_timer(0.1, self.timer_callback)
|
self._timer = self.create_timer(0.1, self.timer_callback)
|
||||||
|
|
||||||
|
# TODO: переделать процесс спавна, должен сформировать все proto файлы, после чего заспавнить все объекты
|
||||||
def timer_callback(self):
|
def timer_callback(self):
|
||||||
|
# TODO: здесь должен получать объекты
|
||||||
if self._spawned_count >= self._object_count:
|
if self._spawned_count >= self._object_count:
|
||||||
self.get_logger().info(f"All {self._object_count} objects spawned")
|
self.get_logger().info(f"All {self._object_count} objects spawned")
|
||||||
self._timer.cancel()
|
self._timer.cancel()
|
||||||
@@ -39,6 +47,7 @@ class ObjectSpawner(Node):
|
|||||||
return
|
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 = '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)
|
req = SpawnNodeFromString.Request(data=data, check_fields=True)
|
||||||
self.get_logger().info(
|
self.get_logger().info(
|
||||||
@@ -58,6 +67,10 @@ class ObjectSpawner(Node):
|
|||||||
self._call_in_progress = False
|
self._call_in_progress = False
|
||||||
self._spawned_count += 1
|
self._spawned_count += 1
|
||||||
|
|
||||||
|
# Вспомогательные методы формирования кода для спавна объектов
|
||||||
|
def _create_group(self, children: list[str]) -> str:
|
||||||
|
return f"DEF OBJECTS Group {{children [{" ".join(children)}]}}"
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user