-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import numpy as np | ||
|
||
import drake_ros.core | ||
from drake_ros.core import ClockSystem | ||
from drake_ros.core import CameraInfoSystem | ||
from drake_ros.core import RosInterfaceSystem | ||
|
||
from pydrake.common import FindResourceOrThrow | ||
from pydrake.multibody.parsing import Parser | ||
from pydrake.systems.analysis import Simulator | ||
from pydrake.systems.framework import DiagramBuilder | ||
from pydrake.systems.sensors import CameraInfo | ||
|
||
|
||
def main(): | ||
# Create a Drake diagram | ||
builder = DiagramBuilder() | ||
# Initialise the ROS infrastructure | ||
drake_ros.core.init() | ||
# Create a Drake system to interface with ROS | ||
sys_ros_interface = builder.AddSystem(RosInterfaceSystem('camera_info')) | ||
ClockSystem.AddToBuilder(builder, sys_ros_interface.get_ros_interface()) | ||
camera_info_system = CameraInfoSystem.AddToBuilder(builder, sys_ros_interface.get_ros_interface()) | ||
|
||
intrinsics = CameraInfo( | ||
width=640, | ||
height=480, | ||
fov_y=np.pi/4, | ||
) | ||
|
||
camera_info_system[0].set_camera_info(intrinsics) | ||
|
||
# Build the complete system from the diagram | ||
diagram = builder.Build() | ||
|
||
# Create a simulator for the system | ||
simulator = Simulator(diagram) | ||
simulator.Initialize() | ||
simulator_context = simulator.get_mutable_context() | ||
simulator.set_target_realtime_rate(1.0) | ||
|
||
# Step the simulator in 0.1s intervals | ||
step = 0.1 | ||
while simulator_context.get_time() < float('inf'): | ||
next_time = min( | ||
simulator_context.get_time() + step, float('inf'), | ||
) | ||
simulator.AdvanceTo(next_time) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |