アプリとサービスのすすめ

アプリやIT系のサービスを中心に書いていきます。たまに副業やビジネス関係の情報なども気ままにつづります

install ubuntu 22.04 to window PC via USB

1 erase Partition on sd-card

# erase FAT32 area in USB CARD
$ diskutil eraseDisk JHFS+ MYDISKNAME disk2

# check state
$ diskutil list

referring site
MacOS diskutilコマンドを使ってGUIのディスクユーティリティでは見えないボリュームを削除する #Mac - Qiita

How to Delete Partition on Mac? How to Remove It on a Hard Drive?

2 install ubuntu img to USB

download Server install image 「ubuntu-22.04.5-desktop-amd64
1. unmount

$ diskutil unmountDisk /dev/disk2

2. use flash and install
in the case of CUI

# it takes some time. you can check how it proceeds by 「Ctrl + T」
$ sudo dd if=ubuntu-22.04.5-desktop-amd64.iso of=/dev/disk2 bs=1m

3 make ubuntu PC
How to put a Linux ISO onto a USB stick and make it bootable on a Mac — The Ultimate Linux Newbie Guide
enter 'BIOS' in window and install ubuntu
=> launch PC and push Enter 4 times or more and F1.
=> enter BIOS. security => secure boot => secure Boot 「ON」 Allow Microsoft 3rd party UEFI CA 「ON」
=> save and exit => push Enter 4 times or more and F12.
=> BOT menu => USB HDD~ (Verbatim STORE N GO)
youtu.be

4 after install
if you can succeed peacefully, erase the ubuntu img from USB.

$ diskutil eraseDisk JHFS+ MYDISKNAME disk2

if you leave it without doing anything, USB may be broken.

ros2のツール一覧まとめ[2025/01/16]

1. rosbag

# 必要ライブラリinstall
sudo apt install ros-${ROS_DISTRO}-plotjuggler-ros
sudo apt install sqlite3


rosbagを作ってみる。

ros2 bag record -o all.bag -a
# or 
ros2 bag record -o all.bag /topic_a /topic_b

# all.bag directory is created
#all.bag
#├── all.bag_0.db3
#└── metadata.yaml

dbファイルと metadata.yamlが作成される。

rosbag再生
$ ros2 bag play all.bag

$ ros2 bag play <rosdir>/ -r 0.2 -s sqlite3 --clock
# -r で倍速指定

# rosbag topic 確認
ros2 bag info <rosbag directry>


このうちmetadata.yamlはトピック一覧などが書かれた補助情報。
rosbag本体はall.bag_0.db3。
この本体がどういった形式になっているかはmetadata.yamlに書かれてる。


sqlite3 で中身を確認

sqlite3 data.bag/data_0.db3
>>>
sqlite> .tables
# messages  metadata  schema    topics
sqlite> .schema


metadata.yamlがない場合

# metadata.yamlを作成
$ ros2 bag reindex <rosbag_dir> -s sqlite3
# >> [INFO] [1737090846.303553233] [rosbag2_cpp]: Reindexing complete.


plotjuggler

PlotJugglerは、データの可視化やリアルタイムモニタリングに特化したros2のツール。簡単に言うと、「データをグラフで見やすく表示し、リアルタイムで観察・分析できるソフトウェア」。



特徴
・リアルタイムモニタリング
データがリアルタイムで変化する様子をその場で観察できるので、ロボットやセンサーの動作確認に便利。
・多くのデータ形式をサポート
CSVファイル、ROS(Robot Operating System)のトピック、JSON形式など、多くのデータ形式を読み込むことができる。


利用シーン
・ロボット開発
センサーや制御システムのデータをリアルタイムで可視化し、動作の改善や問題発見に役立ちます。
機械学習
学習中のデータや予測結果をリアルタイムで確認して、モデルの調整を効率化します。
・実験データの分析
科学や工学の実験結果を手軽に可視化し、分析を行います。


plotjugglerをrosbagで可視化

# download rosbag file from 
gdown -O ~/autoware_map/ 'https://docs.google.com/uc?export=download&id=1sU5wbxlXAfHIksuHjP3PyI2UVED8lZkP'
unzip -d ~/autoware_map/ ~/autoware_map/sample-rosbag.zip
# run plotjuggler 
ros2 run plotjuggler plotjuggler


SWAP realse

# 状況確認
free -h

#現在のSWAP削除
sudo swapoff /swapfile
sudo rm /swapfile

# 新しいswapfile作成
sudo fallocate -l 32G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# 反映されてるか確認
free -h

・参考サイト
GitHub - facontidavide/PlotJuggler: The Time Series Visualization Tool that you deserve.

Jetson Orin NanoにROS2(humble)をinstall (2024/10)

Jetson Orin NanoにROS2 (humble)をinstallする方法メモ。

Jetson Orin Nanoのsetup後にROS2をinstallした。
trafalbad.hatenadiary.jp



ROS2には

Humble Hawksbill(LTS)Iron Irwini(latest release)があるが、
安定してるHumble Hawksbill(LTS)をinstallした。

JetPack 6.1
ubuntu 22.04
・ROS2 Humble

1. Setup Locale

Locale(言語や単位, 記号, 日付, 通貨などの表示規則の集合のこと)のsetup。

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8


2. ROS2 Repository

ROS2 パッケージ用のRepositoryをinstall

# necessary tools
sudo apt update
sudo apt install -y curl gnupg2 lsb-release software-properties-common

# ROS2 Repository's GPG key
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

# add ROS2 Repository to your Jetson 
sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'


3. install ROS2 / setup environment

sudo apt update

# install ROS 2 Humble
sudo apt install ros-humble-desktop

# setup env
source /opt/ros/humble/setup.bash
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc


Ironのケース

sudo apt install ros-iron-desktop
source /opt/ros/iron/setup.bash
echo "source /opt/ros/iron/setup.bash" >> ~/.bashrc
source ~/.bashrc


4. install tools

ROS 1では rosbuild や catkin が使われてるけど、
ROS2ではbuild toolsにcolconが使われてる。


ROS1ではcatkinを用いたビルドを行っていました.catkinは直接cmakeのみを扱います.一方,ROS2では,colconと呼ばれるメタビルドシステムを用います.colconは依存関係を考慮してパッケージのビルド順を決め,ビルドを実行します.ビルドの方法は各パッケージに任せるので,cmakeによらず複数のビルドタイプを選択可能です(ROS2チュートリアル 体験記 (2/3) | Tokyo Opensource Robotics Kyokai Association)

# install 
sudo apt install python3-colcon-common-extensions

# install resdep
sudo apt install python3-rosdep2
sudo rosdep init
rosdep update

これでROS2のinstallは完了したはず

5 テスト

ROS2を動かしてみる

ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp listener

色々変更はあるけど現時点でわかってるのは

・ROS2のlaunchファイルは,xml形式からpython形式になったということ
・ROS1におけるrospyはrclpyに,roscppはrclcppに変更
・roscoreは必要ない通信形式

6 その他のsetup

Jetson Orin NanoのPerformanceの最大化

sudo nvpmodel -m 0
sudo jetson_clocks

turtlesim

sudo apt update
sudo apt install ros-humble-turtlesim
# Check that the package is installed:
ros2 pkg executables turtlesim
>>
turtlesim draw_square
turtlesim mimic
turtlesim turtle_teleop_key
turtlesim turtlesim_node
# start 
# terminal 1
ros2 run turtlesim turtlesim_node
# terminal 2
ros2 run turtlesim turtle_teleop_key
# terminal 3
rqt_graph


ROS2で試しにbuild

# git clone source code
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone https://github.com/ros2/ros2.git -b humble src/ros2

# install dependencies by rosdep
rosdep install --from-paths src --ignore-src -r -y

# build workspace
colcon build --symlink-install

basicなフォルダ構成はこんな感じ

Jeston@orin:~/Downloads/ros2_ws$ tree
.
├── build
│   └── COLCON_IGNORE
├── install
│   ├── COLCON_IGNORE
│   ├── local_setup.bash
│   ├── local_setup.ps1
│   ├── local_setup.sh
│   ├── _local_setup_util_ps1.py
│   ├── _local_setup_util_sh.py
│   ├── local_setup.zsh
│   ├── setup.bash
│   ├── setup.ps1
│   ├── setup.sh
│   └── setup.zsh
├── log
│   ├── build_2024-10-21_20-32-47
│   │   ├── events.log
│   │   └── logger_all.log
│   ├── COLCON_IGNORE
│   ├── latest -> latest_build
│   └── latest_build -> build_2024-10-21_20-32-47
└── src
    └── ros2
        ├── README.md
        └── ros2.repos

ROS2を無事にinstallできた。

Jetson Orin Nano のセットアップ方法 2024/10

Jetson Orin Nanoでないといろいろ困るので、Orin Nano購入した。なのでsetup方法まとめ


前回の記事のとほとんどからないけど、いくつかパーツが違うので以下を購入した。
trafalbad.hatenadiary.jp


電源ケーブルDELL/HP用3ピンソケット(メス)⇔2ピンプラグ(オス)

Amazonベーシック DisplayPort (ディスプレイポート) -- HDMI 変換ケーブル

JetPack


例によってJetPackJetPack SDKのページからダウンロード。

versionはJetPack==6.1

JetPack 6.1 のデフォルトversion
ubuntu 22.04.5 (lsb_release -a)
Python 3.10.12
opencv 4.8.0 (dpkg -l | grep libopencv)
・cuda 12.6 (nvidia-smi)
Nvidia driver 540.4.0

GUIの設定

Google chromiumのインストール
・日本語にキーマボードを変換


CUI で Install & update

# update 
$ sudo apt-get update 
$ sudo apt-get upgrade
$ sudo apt dist-upgrade

# pip3 install
$ sudo apt install gfortran libopenblas-base libopenmpi-dev libopenblas-dev libjpeg-dev libv4l-dev python3-pip
$ sudo pip3 install -U pip
$ sudo pip3 install cython numpy tqdm scikit-learn

# install tree
$ sudo apt install tree


VNC設定

あとで

PCからJetson NanoをROSのinstall & 遠隔操作とsshログイン[2024/08]

ホストPCから大体ハードウェアのJetson NanoをROSの遠隔操作とsshでログインまでの備忘録

目次
1 Jetson Nanoのセットアップ
2.Jetson NanoにROSのinstall
3.パッケージ等の作成
4.ホストPCからJetson NanoをROSで遠隔操作
5. ホストPCからJetsonへsshでログイン

1 Jetson Nanoのセットアップ

まず以前の記事と同じようにJetsonのセットアップから。

今回は動作確認が取れてるJetPack==4.3のMicro SDカードに焼いた。

https://trafalbad.hatenadiary.jp/entry/2021/08/05/220814trafalbad.hatenadiary.jp


# SDカードは/dev/disk4パーティションの容量確保
$ sudo diskutil partitionDisk /dev/disk4 1 GPT "Free Space" "%noformat%" 100% 
>>>>
### Started partitioning on disk4
### Unmounting disk
### Creating the partition map
### Waiting for partitions to activate
### Finished partitioning on disk4

Etcherで書き込み。



2.Jetson NanoにROSのinstall

Jetson Nano(JetPack:4.3)環境
ubuntu 18.04.5 LTS
CMake 3.10.2
Python 3.6.9
Opencv 4.1.1


Jetsonにopencvシンボリックリンク作成

Jetson起動してubuntuをinstallする設定をした後、18.04なのでMerodicをinstall

まず「Software」から「Firefox ウェブブラウザ」をinstall。

# Jetson起動してupdate
sudo apt update
sudo apt upgrade
# 必要パッケージのinstall
sudo apt install wget curl git vim tree

# python2 に変換
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

JetPack==4.3ではopencvがinstall済みだけどパスが違うので、シンボリックリンクを作る

sudo ln -s /usr/include/opencv4/ /usr/include/opencv

ROSのインストール

# ROSのinstall
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

# public keyの登録
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# rosと関連パッケージのinstall
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc 
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo rosdep init
rosdep update

# ワークスペースの作成と登録
mkdir -p catkin_ws/src && cd catkin_ws # (pwd==/home/user/catkin_ws)
catkin_make 
echo "source /home/user/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

# working spaceの登録
#cd ~/catkin_ws/src
#catkin_init_workspace
#cd ~/catkin_ws
#catkin_make
#source ~/.bashrc


# パッケージの作成
cd ~/catkin_ws/src
catkin_create_pkg ros_start rospy roscpp std_msgs
cd ~/catkin_ws
catkin_make
# 作成できてるかcheck
roscd ros_start
#### => ~/catkin_ws/src/ros_start に移動できればOK
# 再起動
sudo reboot


3.パッケージ等の作成

今まで通りにTopic通信や独自Serviceの作成もホスト同様にできる。

trafalbad.hatenadiary.jp

trafalbad.hatenadiary.jp


4. ホストPCからJetson NanoをROSで遠隔操作

# ホストPC側
$ hostname -I | cut -d' ' -f1
### 192.168.10.111

# Jetson Nano側
$ hostname -I | cut -d' ' -f1
### 192.168.10.102


環境変数の設定

# PC(ROS_MASTER)側に、ROS_MASTER/ROS_IPを設定
export ROS_MASTER_URI=http://192.168.10.111:11311  # ROS_MASTER側のアドレスを設定
export ROS_IP=192.168.10.111                      # 自分のIPアドレスを設定

# Jetson側、ROS_MASTER/ROS_IPを設定
export ROS_MASTER_URI=http://192.168.10.111:11311
export ROS_IP=192.168.10.102


roscore/turtlesim起動

# PC(ROS_MASTER)側、roscore/turtlesim_nodeを起動
roscore
rosrun turtlesim turtlesim_node

# Jetson側、turtle_teleop_keyを起動
rosrun turtlesim turtle_teleop_key

### Jetson側でturtleを操作できればOK

ホストPCからJetsonをROSで操作できた

5. ホストPCからJetsonへsshでログイン

ホストPC側で操作

$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096  # 秘密鍵/公開鍵ペア生成(鍵の名前を"jetson"にしておく)
$ mv id_rsa jetson && mv id_rsa.pub jetson.pub
# ~/.ssh/configファイルの作成
Host 任意の名称(接続時に使用)
    Hostname 接続先のIPアドレス/ドメイン名
    User ユーザ名
    Port ポート番号
    Identityfile 鍵ファイルのパス
    ServerAliveInterval 秒(自動切断防止設定。後述)

# example
Host jetson
    Hostname 192.168.10.102
    User jetson
    Port 22
    Identityfile ~/.ssh/jetson
    ServerAliveInterval 60

これでホストPCから、jetsonにでリモートログインできた。

ssh jetson 
Jetson pass>>>
>>>

loginできた。次はjetsonからrealsense-Laidarのデータ取得

参考

Jetson Nano/PC間でROS接続する
Getting Started with ROS on Jetson Nano
ROS noeticでImportError: No module named rospkgを解決する

ROSのインストール(noetic-desktop-full)と基礎動作確認まで[2024/08]

ロボットを動かすミドルウェアrosを使うために、rosのinstallと簡単な初期動作の備忘録。
rosのバージョンはNoetic。






ROSのバージョン表
ディストリビューション Ubuntuのバージョン サポート期限
Indigo
14.04
2019年5月
Kinetic
14.04
2021年5月
Melodic
18.04
2023年5月
Noetic
20.04
2025年5月

Windows 11をOSごとubuntu20.04に入れ替えた。
(ubuntu 18.04だとwifiを認識しなかったり、マウスパッドが反応しないとかのエラーが出たので20.04がおすすめ)
(20.04だとcmakeとpython3はすでに入ってる。)


環境
OS Ubuntu : 20.04.3 LTS
CMake :3.16.3
Python :3.8.10
opencv : 4.2.0(rosのinstall時に入る)

目次
1. ROSのインストール
2. ROSのインストール確認
3. Opencvシンボリックリンクの作成
4. ROSパッケージの作成
5. 簡単なROSの基本動作

1. ROSのインストール

# update と再起動
sudo apt-get update
sudo apt-get upgrade
sudo reboot

# 必須パッケージのinstall
sudo apt install curl git wget vim tree
sudo apt install -y python3-pip

****注意 conda(anaconda3)はinstallしたらrosのinstall時にエラーが起きた

# パスの登録
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
# public keyの登録
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

# rosと関連パッケージのinstall
sudo apt update 
sudo apt install ros-noetic-desktop-full
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential

# rosdepの初期化(エラーが出たら$ sudo rm /etc/ros/rosdep/sources.list.d/20-default.list)
sudo rosdep init
rosdep update

# ワークスペースの作成と登録
mkdir -p catkin_ws/src && cd catkin_ws
catkin_make # (If It's ok : pwd ==/mnt/c/Users/Downloads/place/catkin_ws)

# "source /opt/ros/noetic/setup.bash" と書き換え
echo "source /mnt/c/Users/Downloads/place/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc


2. ROSのインストール確認

インストールできてるかチェック

# 1つ目
$ echo $ROS_PACKAGE_PATH
>>>>
/mnt/c/Users/Downloads/place/catkin_ws/src:/opt/ros/noetic/share
と表示されればOK
# 2つ目
$ roscore
#色々表示されればOK

Noeticのインストール用script(install.sh)

# !/bin/sh
# resister path to install ros & get public key to download
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
# install ros(melodic)
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential

# sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
sudo rosdep init
rosdep update

# ROSのワーキングスペースの作成
mkdir -p catkin_ws/src && cd catkin_ws
catkin_make
# register worksopace
echo "source /mnt/c/Users/Downloads/place/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
# To check
echo $ROS_PACKAGE_PATH 


ROSのuninstall(全部削除)

# uninstall ros completely 
$ sudo apt-get purge ros-*
$ sudo apt-get autoremove


3. Opencvシンボリックリンクの作成

opencvのパスが/usr/include/opencv4/opencv2になってるのでシンボリックリンクを作る。

sudo ln -s /usr/include/opencv4/ /usr/include/opencv

4. ROSパッケージの作成

# 基本パッケージの作成(catkin make でbuild)
cd ~/catkin_ws/src
catkin_create_pkg ros_start rospy roscpp std_msgs
>>>>
#### Created file ros_start/package.xml
#### Created file ros_start/CMakeLists.txt
#### Created folder ros_start/include/ros_start
#### Created folder ros_start/src
#### Successfully created files in /mnt/c/Users/Downloads/place/catkin_ws/src/ros_start. Please adjust the values in package.xml.



# catkin make
cd ~/catkin_ws
catkin_make
>>>
####
#### Running command: "make -j8 -l8" in "/mnt/c/Users/Downloads/place/catkin_ws/build"
####

# 作成できてるかcheck
roscd ros_start
#### => ~/catkin_ws/src/ros_start に移動できればOK

Version check

# ros 
$ echo $ROS_DISTRO

# ubuntu 
$ lsb_release -d


5. 簡単なROSの基本動作

2. ROSでHello World



1. ターミナルを2つ開く

2. 一つ目のターミナルで
roscore

3. 2つ目のターミナルでpythonスクリプト実行

# hello.py
import rospy
rospy.init_node('hello') # ノード初期化
rospy.loginfo('Hello World')
rospy.spin()
$ python3 hello.py
>>>
[INFO][WallTime: 1456677777.322475] Hello World

ROSでHello Worldできた。
GUIも使えるし、VPNにもつなぎやすいので、Windowsでwslより、ubuntuでOSを入れ替える方がいい。


参考サイト

『ROS Noetic』のインストール

Good and bad example with MiDaS Depth Estimation (experiment)

I examined why MiDaS can work well or not, depending on images.
If Midas work well, there has to be specific patterns. Also there has to be bad patterns either.


Then, in order to confirm there would be better and bad pattern for MiDaS Depth estimation. Especially in specific condition in image.
I took experiment with 3 patternps this time.

This is memo for my own sake, so I wrote this article as I like, not as formal.

bad pattern

This is bad pattern.

Original image

Predicted image


Why this is bad pattern

1. The target object for prediction are small
2. Very close object are in sight and disturbing prediction. In this case, edge of car is the one.
3. The image had to focus on plotting target object for estimation mainly.


Total prediction stream

Better pattern

This is better pattern. I changed image conditions.

Changed conditions

1. I cropped height and width both. Also erase unnecessary parts both side.
2. Let target objects for estimation plot bigger than previous bad pattern.
Original image


Predicted image


Why this is better pattern

1. Target object for prediction in image are plot big enough to predict.
2. Cropping not moving sight(unnecessary parts) and these effect made prediction better

Total prediction stream(gif)


Best pattern

This is best pattern. I changed image conditions more.


Changed conditions

1. Crop height and erase unnecessary parts.
2. I didn't crop width to keep image balance, which means adjusting image size well-balanced enough to see target object and easy enough to predict
3. Let target objects for estimation plot big


Original image


Predicted image


Why this is best pattern

1. Target object for prediction in image are plot big enough to predict.
2. Image size are well-balanced so it became easy to predict.
=> in previous case, cropped too many, though target objects are big enough to predict. However image size are unbalanced for prediction.

3. The target object is big and image size is well-balanced. These 2 make prediction work better than any pattern

Total prediction stream(gif)


To make MiDaS work better, you have to adjust conditions good for prediction.