<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kazuya Hirotsu on Medium]]></title>
        <description><![CDATA[Stories by Kazuya Hirotsu on Medium]]></description>
        <link>https://medium.com/@kazuyahirotsu?source=rss-2f6928ce296b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AcnQMaC3j967V48k</url>
            <title>Stories by Kazuya Hirotsu on Medium</title>
            <link>https://medium.com/@kazuyahirotsu?source=rss-2f6928ce296b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:17:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kazuyahirotsu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create RGB-D datasets with Unreal Engine]]></title>
            <link>https://medium.com/@kazuyahirotsu/create-rgb-d-dataset-with-unreal-engine-a6849ecb2438?source=rss-2f6928ce296b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6849ecb2438</guid>
            <category><![CDATA[dataset]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[unreal-engine]]></category>
            <dc:creator><![CDATA[Kazuya Hirotsu]]></dc:creator>
            <pubDate>Wed, 13 Dec 2023 01:02:15 GMT</pubDate>
            <atom:updated>2023-12-19T07:51:28.804Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Using Realistic 3D Simulation, we can easily create an RGB-D dataset with accurate ground-truth data.</p><p>In this article, we will use Unreal Engine 4 mainly because of UnrealCV library which enables us to get depth data, which is not readily available in most 3D simulation software.</p><p><a href="https://unrealcv.org/">UnrealCV</a></p><h3>Setup</h3><p>(My environment is macOS Big Sur 11.7.10)</p><p><strong>Install Unreal Engine 4 (4.27.2)</strong></p><p>Since UnrealCV is not compatible with UE5, we need to use UE4. The latest version for me is 4.27.2</p><p>You just need to follow this page for installation.</p><p><a href="https://www.unrealengine.com/en-US/download">Download Unreal Engine</a></p><p><strong>Create a new project and Install UnrealCV add-on</strong></p><p>Follow this page.</p><p>(there is no need for git checkout at the moment since the master branch is at 4.27-stable)</p><p><a href="https://docs.unrealcv.org/en/latest/plugin/custom_scene.html">Basic usage in a new project - UnrealCV 1.0.1 documentation</a></p><p>press ` to open the built-in console and try commands like</p><pre>vget /objects</pre><p><strong>Install UnrealCV Python Library</strong></p><pre>pip install unrealcv</pre><h3>Development</h3><p>Most of the commands used here are documented on this page.</p><p><a href="https://docs.unrealcv.org/en/latest/reference/commands.html">Command System - UnrealCV 1.0.1 documentation</a></p><p><strong>Connect to UE4</strong></p><pre>from unrealcv import client<br>client.connect()<br>if not client.isconnected():<br>    print(&#39;UnrealCV server is not running.&#39;)</pre><p>If it won’t connect to the server, reopen and run the project again. (<a href="https://docs.unrealcv.org/en/latest/reference/issues.html#platform-specific-issues:~:text=When%20in%20mac%2C%20the%20server%20can%20not%20detect%20the%20socket%20disconnection.%20If%20the%20first%20time%20connection%20is%20successful%20and%20the%20second%20time%20is%20faile.%20Then%20please%20close%20and%20re%2Dopen%20it%20again.">When in mac, the server can not detect the socket disconnection.</a>) This is why we want to use Jupyter Notebook (ipynb file) instead of a Python file.</p><p>If that doesn’t work either, check port 9000 and kill the process running there.</p><pre>$ lsof -i :9000<br>COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME<br>python3.1 12643 hiro   51u  IPv4 0xa89505cb757e330f      0t0  TCP localhost:cslistener (LISTEN)</pre><p>Something is running in this one, so kill it like this.</p><pre>$ kill -9 12643</pre><p><strong>Check the config</strong></p><pre>res = client.request(&#39;vget /unrealcv/status&#39;)<br># The image resolution and port is configured in the config file.<br>print(res)</pre><p><strong>Save images (RGB, object mask, normal)</strong></p><pre>res = client.request(&#39;vget /camera/0/lit /Users/hiro/warehouse_drone/simulation/ue4_dataset_generation/lit.png&#39;)<br>print(res)<br>res = client.request(&#39;vget /camera/0/object_mask /Users/hiro/warehouse_drone/simulation/ue4_dataset_generation/object_mask.png&#39;)<br>print(res)<br>res = client.request(&#39;vget /camera/0/normal /Users/hiro/warehouse_drone/simulation/ue4_dataset_generation/normal.png&#39;)<br>print(res)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*zL0lAbRbOHN-B-W3II9L1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*-VAkCkPOPn3bK_eue153eA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*8FsPioEMzjG1TdWZKIljYA.png" /><figcaption>This scene is a bit modified from the default scene</figcaption></figure><p>If the camera is not working well, try this.</p><blockquote>Drag a Fusion Camera Actor from the left side &quot;Place Actors&quot; panel. And get the segmentation mask from camera id 1.</blockquote><p><a href="https://github.com/unrealcv/unrealcv/issues/186#issuecomment-707973151">UnrealCV Problems with UE 4.22.3 · Issue #186 · unrealcv/unrealcv</a></p><p><strong>Save and show depth image</strong></p><pre>import numpy as np<br>from matplotlib import pyplot as plt<br>res = client.request(&#39;vget /camera/0/depth /Users/hiro/warehouse_drone/simulation/ue4_dataset_generation/depth.npy&#39;)<br>img_array = np.load(&#39;depth.npy&#39;)<br>plt.imshow(img_array)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*CDgQ48pyrTvRaX0TdgkObQ.png" /><figcaption>This scene is a bit modified from the default scene</figcaption></figure><p>If the image looks like this, it’s the problem with the camera location, so change the location with the following command first. (it is colliding with something)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*mDKJpo7Sqy584OrAW4hrLw.png" /></figure><p><strong>Get and Set Camera location and rotation</strong></p><pre>res = client.request(f&#39;vget /camera/0/location&#39;)<br>print(res)<br>res = client.request(f&#39;vget /camera/0/rotation&#39;)<br>print(res)<br><br>res = client.request(f&#39;vset /camera/0/location 150 0 200&#39;)<br>print(res)<br>res = client.request(f&#39;vset /camera/0/rotation 0 -180 0&#39;)<br>print(res)</pre><p><strong>Get and Set Object location, rotation, and scale</strong></p><p>First, let’s add a cube in the scene using Unreal Editor (not Python) and set the mobility of that object to movable.</p><p>(You can only change the location of the movable objects)</p><p>Then you can try these commands.</p><pre>res = client.request(f&#39;vget /object/Cube/location&#39;)<br>print(res)<br>res = client.request(f&#39;vget /object/Cube/rotation&#39;)<br>print(res)<br>res = client.request(f&#39;vget /object/Cube/scale&#39;)<br>print(res)<br><br>res = client.request(f&#39;vset /object/Cube/location -500 0 0&#39;)<br>print(res)<br>res = client.request(f&#39;vset /object/Cube/rotation 0 0 0&#39;)<br>print(res)<br>res = client.request(f&#39;vset /object/Cube/scale 1 20 30&#39;)<br>print(res)</pre><h3>Go Further</h3><p>Combining these commands, you can create an RGB-D dataset capturing various object locations and rotation with different camera locations and rotation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6849ecb2438" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[drone simulation environment setup (PX4, ROS)]]></title>
            <link>https://medium.com/@kazuyahirotsu/drone-simulation-environment-setup-px4-ros-89314a3fba42?source=rss-2f6928ce296b------2</link>
            <guid isPermaLink="false">https://medium.com/p/89314a3fba42</guid>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[gazebo]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[drones]]></category>
            <dc:creator><![CDATA[Kazuya Hirotsu]]></dc:creator>
            <pubDate>Fri, 01 Dec 2023 06:52:52 GMT</pubDate>
            <atom:updated>2023-12-01T06:52:52.393Z</atom:updated>
            <content:encoded><![CDATA[<h3>drone simulation environment setup (PX4, ROS2, gazebo)</h3><h3>Introduction</h3><p>There are many ways to simulate drones, but this article focuses on a setup aimed at ultimately using the same code for autonomous drone flight on an actual drone.</p><ul><li>PX4: An open-source flight controller, easy to use with hardware like pixhawk</li><li>ROS2: An open-source framework for robots, ROS is also fine</li><li>gazebo: An open-source 3D simulator, lightweight enough for laptop use</li></ul><p>In theory, using pixhawk and an onboard Ubuntu computer should make it easy to transfer to an actual drone.</p><h3>Setup</h3><p>First, install Ubuntu 22.04.<br><a href="https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview">https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview</a></p><p>Then install PX4, ROS2, and gazebo.</p><p><a href="https://docs.px4.io/main/en/ros/ros2_comm.html">ROS 2 User Guide | PX4 User Guide (main)</a></p><p>At this point, you should be able to move a drone in gazebo using sample scripts with ROS2 and PX4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZNOe92EHThgarcGo1pnhQ.png" /></figure><h3>Development</h3><h3><strong>Camera Data Stream</strong></h3><p>To bring camera image data from gazebo topics to ROS2 requires a bit of work.</p><p>Install ros-humble-ros-gzgarden:</p><pre>sudo apt install ros-humble-ros-gzgarden</pre><p>You need to create a bridge with either ros_gz_image or ros_gz_bridge.</p><pre>ros2 run ros_gz_image image_bridge /camera</pre><pre>ros2 run ros_gz_bridge parameter_bridge /camera@sensor_msgs/msg/Image@ignition.msgs.Image</pre><p>ros_gz_bridge can be used for other topics (like depth) as well, so it seems more versatile.</p><pre>ros2 run ros_gz_bridge parameter_bridge /camera@sensor_msgs/msg/Image@ignition.msgs.Image <br>/camera_info@sensor_msgs/msg/CameraInfo@ignition.msgs.CameraInfo /depth_camera/points@sensor_msgs/msg/PointCloud2@gz.msgs.PointCloudPacked /depth_camera@sensor_msgs/msg/Image@ignition.msgs.Image</pre><p><a href="https://github.com/gazebosim/ros_gz/tree/ros2/ros_gz_bridge">ros_gz/ros_gz_bridge at ros2 · gazebosim/ros_gz</a></p><h3>Keyboard Control</h3><p>Since PX4’s sample code is waypoint-based, you’ll need code to control things like the drone’s speed for keyboard operation.</p><p>This code makes it easy to use the keyboard, but note that it uses mavsdk, which is different from the px4_ros_com sample code.</p><p><a href="https://github.com/monemati/PX4-ROS2-Gazebo-YOLOv8/blob/main/keyboard-mavsdk-test.py">PX4-ROS2-Gazebo-YOLOv8/keyboard-mavsdk-test.py at main · monemati/PX4-ROS2-Gazebo-YOLOv8</a></p><h3>Trouble Shooting</h3><p>I spent some time debugging this issue, so I’m including it just in case.</p><p>When trying to start PX4, I encountered this error:</p><pre>ERROR [gz_bridge] timed out waiting for clock message<br>ERROR [gz_bridge] Task start failed (-1)<br>ERROR [init] gz_bridge failed to start<br>ERROR [px4] Startup script returned with return value: 256</pre><p>This command fixed it:</p><pre>pkill -9 ruby<br>unset GZ_IP<br>unset GZ_PARTITION</pre><p>Reference:</p><p><a href="https://discuss.px4.io/t/px4-sitl-stopped-working-with-gazebo-garden/34513">PX4-SITL stopped working with Gazebo Garden</a></p><p>The PX4 user forum is very active, so it’s recommended to consult there if you get stuck in debugging.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89314a3fba42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to start developing drone with PX4 and raspberry pi]]></title>
            <link>https://medium.com/@kazuyahirotsu/how-to-start-developing-drone-with-px4-and-raspberry-pi-7b3db3575e1c?source=rss-2f6928ce296b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b3db3575e1c</guid>
            <category><![CDATA[drones]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Kazuya Hirotsu]]></dc:creator>
            <pubDate>Tue, 23 May 2023 14:50:55 GMT</pubDate>
            <atom:updated>2023-05-23T14:50:55.055Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. hardware setup</h3><ul><li><a href="https://holybro.com/products/px4-development-kit-x500-v2">PX4 Development Kit — X500 v2</a></li><li>raspberry pi</li></ul><p>Follow <a href="https://docs.px4.io/main/en/companion_computer/pixhawk_rpi.html">the official documentation</a> to connect your raspberry pi to your pixhawk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QnrQlky7JL3LPLlni4_xg.jpeg" /></figure><h3>2. software setup</h3><p>Follow <a href="https://docs.px4.io/main/en/companion_computer/pixhawk_rpi.html">the official documentation</a></p><p>If you are using raspi OS, config file below is at /boot/config.txt instead of /boot/firmware/config.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NwG_iXOw84INRbyMhj7SLg.png" /></figure><p>In my pixhawk, UXRCE_DDS_CFGand SER_TEL2_BAUD below were not found, but after setting up MAV_1_CONFIG = TELEM2 , SER_TEL2_BAUD has appeared and without setting up UXRCE_DDS_CFG , test with mavproxy was working fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RYPvFITEFhhE9xpyryS0ew.png" /></figure><h3>3. start coding</h3><p>At this point, you can choose your preferred language or platform to start developing. If you want to use symple python setup like me, you can use <a href="https://mavlink.io/en/mavgen_python/">pymavlink</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b3db3575e1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use 3D buildings as obstacles in omnet++/inet]]></title>
            <link>https://medium.com/@kazuyahirotsu/how-to-use-3d-buildings-as-obstacles-in-omnet-inet-e75c6e50d246?source=rss-2f6928ce296b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e75c6e50d246</guid>
            <category><![CDATA[omnetpp]]></category>
            <category><![CDATA[geojson]]></category>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Kazuya Hirotsu]]></dc:creator>
            <pubDate>Tue, 02 May 2023 09:20:06 GMT</pubDate>
            <atom:updated>2023-05-02T09:20:06.022Z</atom:updated>
            <content:encoded><![CDATA[<p>omnet++ uses xml format to describe the obstacles in the 3D environment for simulations as explained <a href="https://inet.omnetpp.org/docs/users-guide/ch-environment.html">here</a>. Since there is no function available that can convert a file of 3d buildings in the city to this xml format, we need to do it manually. In this article, I will explain how to find, download, convert, and use 3D buildings for simulation use in omnet++/inet.</p><ol><li>acquire a file of 3D buildings</li></ol><p>You can use data from open street map (OSM)<br><a href="https://osmbuildings.org/">https://osmbuildings.org/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jq_MkHnieJPN55MUjRJOYw.png" /></figure><p>To download, you can use the url format below as explained <a href="https://osmbuildings.org/documentation/data/">here</a><br>http(s)://({abcd}.)data.osmbuildings.org/0.2/anonymous/tile/15/{x}/{y}.json</p><p>To calculate the tile coordinates from longitude and latitude you want, you can use this python script.</p><pre>import math<br><br>def long_to_x(longitude, zoom):<br>    return int((longitude + 180.0) / 360.0 * (2.0 ** zoom))<br><br>def lat_to_y(latitude, zoom):<br>    return int((1.0 - math.log(math.tan(math.radians(latitude)) + 1 / math.cos(math.radians(latitude))) / math.pi) / 2.0 * (2.0 ** zoom))<br><br>longitude = 13.414041  # Your longitude<br>latitude = 52.537443  # Your latitude<br>zoom = 15  # zoom level<br><br>x = long_to_x(longitude, zoom)<br>y = lat_to_y(latitude, zoom)<br>print(x, y)</pre><p>2. validate geojson file (optional)</p><p>Once you acquire the geojson file from osmbuildings.org, you might want to validate it by visualizing it. You can use this python script for that.</p><pre>import folium<br><br># Create a Map instance<br>longitude = 13.414041  # Your longitude<br>latitude = 52.537443  # Your latitude<br>m = folium.Map(location=[latitude, longitude], zoom_start=15)<br><br># Load GeoJSON file<br>folium.GeoJson(<br>    &quot;export.geojson&quot;,<br>    name=&#39;geojson&#39;<br>).add_to(m)<br><br># Show the map<br>m</pre><p>The output should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORaBA5e8VcwJW9LYOfo1pw.png" /></figure><p>3. convert geojson file to xml file</p><p>For conversion, you can use this python script. In this script, I am converting gps coordinates to cartesian coordinates and using min latitude and min longitude as origin, but you can change the code to suit your needs.</p><pre>import json<br>from xml.etree.ElementTree import Element, SubElement, tostring<br>from xml.dom import minidom<br>import pyproj<br>import numpy as np<br>from tqdm import tqdm<br><br># Convert GPS coordinates to Cartesian coordinates<br>def to_cartesian(lat, lon):<br>    # Calculate UTM zone from longitude<br>    zone = int((lon + 180) / 6) + 1<br><br>    # define the coordinate systems<br>    transformer = pyproj.Transformer.from_crs(&quot;epsg:4326&quot;, f&quot;epsg:326{zone if lat &gt;= 0 else zone + 100}&quot;)<br><br>    x, y = transformer.transform(lat, lon)<br>    return x, y<br><br># Parse the GeoJSON<br>with open(&quot;export.geojson&quot;) as f:<br>    geojson = json.load(f)<br><br># Get the minimum latitude and longitude<br>min_lat = 10**5<br>for feat in geojson[&quot;features&quot;]:<br>    for p in feat[&quot;geometry&quot;][&#39;coordinates&#39;][0]:<br>        min_lat = min(min_lat, p[1])<br>min_lon = 10**5<br>for feat in geojson[&quot;features&quot;]:<br>    for p in feat[&quot;geometry&quot;][&#39;coordinates&#39;][0]:<br>        min_lon = min(min_lon, p[0])<br><br>min_x, min_y = to_cartesian(min_lat, min_lon)<br><br># Create the root element<br>root = Element(&#39;environment&#39;)<br><br># Loop through the features<br>for feature in tqdm(geojson[&#39;features&#39;]):<br>    # Only process polygons<br>    if feature[&#39;geometry&#39;][&#39;type&#39;] == &#39;Polygon&#39;:<br>        # Create the object element<br>        obj = SubElement(root, &#39;object&#39;)<br>        <br>        # Set object attributes<br>        height = feature[&#39;properties&#39;].get(&#39;height&#39;, 10)  # Use height from properties or default to 10<br>        <br>        # Convert the coordinates to metric and generate the shape attribute<br>        shape_coords = []<br>        for coords in feature[&#39;geometry&#39;][&#39;coordinates&#39;][0]:<br>            x, y = to_cartesian(coords[1], coords[0])<br>            x, y = x-min_x, y-min_y<br>            shape_coords.append(f&quot;{x} {y} &quot;)<br><br>        min_metric_coords = np.min(metric_coords, axis=0)<br>        obj.set(&#39;position&#39;, f&quot;min {min_metric_coords[0]} {min_metric_coords[1]} 0&quot;)<br><br>        node_locations.append(list(min_metric_coords)+[height+1])<br><br>        shape = f&quot;prism {height} &quot; + &#39; &#39;.join(shape_coords)<br>        obj.set(&#39;shape&#39;, shape)<br>        <br>        obj.set(&#39;material&#39;, &quot;brick&quot;)<br>        obj.set(&#39;fill-color&#39;, &quot;203 65 84&quot;)<br>        obj.set(&#39;opacity&#39;, &quot;0.8&quot;)<br><br># Generate the XML string<br>xml_string = tostring(root)<br><br># Pretty print the XML<br>xml_pretty = minidom.parseString(xml_string).toprettyxml(indent=&quot;   &quot;)<br><br># Write XML string to file<br>with open(&#39;buildings.xml&#39;, &#39;w&#39;) as f:<br>    f.write(xml_pretty)<br>    <br>print(xml_pretty)</pre><p>4. use it in omnet++</p><p>You can refer to <a href="https://inet.omnetpp.org/docs/tutorials/wireless/doc/step11.html">this article</a> for how to simulate 3D obstacles. It loooks like this in my simulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cAAYLJRqHelBkmH0LiI5Ww.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e75c6e50d246" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>