質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

1344閲覧

python 文字列の扱い

reiya_123

総合スコア57

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2022/03/21 08:25

編集2022/03/21 08:27

前提

ubuntu20.04
python3.8を使用しています

現在、下記のサイトを参考に2次元地図からgazeboのモデルを作ろうとしています。
しかし、元々python2系のコードだったためか文字列の読み込みがうまくいってない状態で様々なサイトを参考に encoding='shift_jis'やencoding='windows-1252'に変えてみたのですがよくわかっていない状態です。
申し訳ございませんがご教示いただけないでしょうか。
よろしくお願いいたします。
https://qiita.com/BEIKE/items/825e62bbd8d92b6d347e#3-map2gazebo%E3%81%A7%E7%94%9F%E6%88%90%E3%81%97%E3%81%9Fmodel%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%83%8A%E3%83%93%E3%82%B2%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B

発生している問題・エラーメッセージ

[ERROR] [1647850354.213820]: bad callback: <bound method MapConverter.map_callback of <__main__.MapConverter object at 0x7fdd9dbdb400>> Traceback (most recent call last): File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback cb(msg) File "/practice_ws/src/map2gazebo/src/map2gazebo.py", line 43, in map_callback mesh.export(f, "stl") File "/.local/lib/python3.8/site-packages/trimesh/base.py", line 2712, in export return export_mesh(mesh=self, File "/.local/lib/python3.8/site-packages/trimesh/exchange/export.py", line 85, in export_mesh result = util.write_encoded(file_obj, export) File "/.local/lib/python3.8/site-packages/trimesh/util.py", line 2118, in write_encoded file_obj.write(stuff.decode(encoding)) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 86: invalid start byte

該当のソースコード

def write_encoded(file_obj, stuff, encoding='utf-8'): """ If a file is open in binary mode and a string is passed, encode and write. If a file is open in text mode and bytes are passed decode bytes to str and write. Parameters ----------- file_obj : file object With 'write' and 'mode' stuff : str or bytes Stuff to be written encoding : str Encoding of text """ binary_file = 'b' in file_obj.mode string_stuff = isinstance(stuff, basestring) binary_stuff = isinstance(stuff, bytes) if not PY3: file_obj.write(stuff) elif binary_file and string_stuff: file_obj.write(stuff.encode(encoding)) elif not binary_file and binary_stuff: #/.local/lib/python3.8/site-packages/trimesh/util.py", line 2118 file_obj.write(stuff.decode(encoding)) else: file_obj.write(stuff) file_obj.flush() return stuff

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

違った原因でした。
noeticの場合、下記のサイトを参考に
https://github.com/shilohc/map2gazebo/issues/1
こちらをダウンロードして
git clone https://github.com/H-HChen/map2gazebo.git
以下のコマンドを打てば、無事にstlファイルを作成することができました。
python3 src/map2gazebo/map2gazebo/map2gazebo_offline.py --map_dir /path/to/map/mememan.pgm --export_dir /path/to/export_dir

投稿2022/03/21 13:21

reiya_123

総合スコア57

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問