ロボクメモ Robojimamemo

ロボットを研究する、ある学生のメモ。日々、勉強したことをメモ代わりに残して共有します(ROS,C++,python,linux,etc...)

byobu 1コマンドで複数のコマンドを実行 screen 編

byobu はロボットやリモートでの作業に便利

以前紹介したbyobuでの複数コマンド実行はbackendがtmuxの人にしか使うことができない。

memo-methods-in-researching.hatenablog.com

ちなみにbackendの変更は
$byobu-select-backend
で変更可能。
screenはそれぞれのwindowに対してユニークな名前がつけられてわかりやすい。 screenコマンドの場合はbyobuに入らなくてもガンガンコマンドをバックプロセスに投げられる。 もう少し工夫した方法はないか。

1. windowの名前の変更 スクリーン内のウィンドウの名前はこのコマンドで変更することができる。
$ echo -ne "\ekhello\e\\"

2. セッション名、window名を指定してコマンドを実行
$ byobu -r <Session> -p <Window> -X stuff "<command>^M"

#!/bin/bash
command_0='echo -ne "\ekhello\e\\\\" && screen && echo robot'
command_1='echo -ne "\ekhello2\e\\\\" && screen && echo research'

session="toaru"
window_bash="bash"

byobu -d -m -S ${session} 
byobu -r ${session} -X stuff "${command_0}^M" 
sleep 1s
byobu -r ${session} -p $window_bash -X stuff "${command_1}^M" 

echo "all done ... "

f:id:shun0612:20181123165225p:plain:w300 f:id:shun0612:20181123165236p:plain:w300

便利

byobu 1コマンドで複数のコマンドを実行 tmux編

byobuでコマンドを一つにして簡単に

ロボットやリモートでプロセスを回すときにはbyobuを使うとネットワークが突然切れても大丈夫。 ssh 先で複数の端末を開いて作業することができる。  http://byobu.org/about.html 

windowのlayoutを保存して復元

1. paneを分ける
縦割り:Shift + F2
横割り:Ctrl + F2
大きさ調整:Alt + Shift + 方向キー

2. 保存
$byobu-layout save <NAME>

f:id:shun0612:20181123161453p:plain:w300

コマンドを指定したpaneに振り分ける

1. 保存したwindowを復元 $ byobu-layout restore <NAME>

2. コマンドの振り分け

#!/bin/bash
window_name="toaru"
byobu-layout restore <NAME> #1.の内容
byobu rename-window $window_name # toaruがそのwindowの名前

byobu send-keys -t $window_name.0 'echo toaru' C-m
byobu send-keys -t $window_name.1 'echo gakusei' C-m
byobu send-keys -t $window_name.2 'echo robot' C-m
byobu send-keys -t $window_name.3 'echo research' C-m  

f:id:shun0612:20181123161525p:plain:w300

便利 screen でやる方法はこちら

memo-methods-in-researching.hatenablog.com

ubuntu16.04でSMACH ロボットの状態遷移を可視化

ロボットの状態遷移ツール

ロボットが複数のタスクをしたり、複数人でロボットを開発するときにはこのような状態遷移の可視化ツールがあると便利。

http://wiki.ros.org/ja/smach

http://wiki.ros.org/smach_viewer

1 . 依存パッケージのインストール(そのままだとpython関係でエラーが出る)  

$sudo add-apt-repository ppa:nilarimogard/webupd8    
$sudo apt-get install python-wxgtk2.8

2 . git clone   

$cd ~/catkin_ws/src/    
$git clone https://github.com/ros-visualization/executive_smach_visualization.git
$git clone https://github.com/ros/executive_smach.git

3 . サンプルコード  

#!/usr/bin/env python

import rospy
import smach
import smach_ros

# define state Foo
class Foo(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['outcome1','outcome2'])
        self.counter = 0

    def execute(self, userdata):
        rospy.loginfo('Executing state FOO')
        rospy.sleep(1)
        if self.counter < 3:
            self.counter += 1
            return 'outcome1'
        else:
            return 'outcome2'


# define state Bar
class Bar(smach.State):
    def __init__(self):
        smach.State.__init__(self, outcomes=['outcome2'])

    def execute(self, userdata):
        rospy.loginfo('Executing state BAR')
        rospy.sleep(1)
        return 'outcome2'
        



# main
def main():
    rospy.init_node('smach_example_state_machine')

    # Create a SMACH state machine
    sm = smach.StateMachine(outcomes=['outcome4', 'outcome5'])

    # Open the container
    with sm:
        # Add states to the container
        smach.StateMachine.add('FOO', Foo(), 
                               transitions={'outcome1':'BAR', 
                                            'outcome2':'outcome4'})
        smach.StateMachine.add('BAR', Bar(), 
                               transitions={'outcome2':'FOO'})

    # Create and start the introspection server
    sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
    sis.start()

    # Execute SMACH plan
    outcome = sm.execute()
    rospy.spin()


if __name__ == '__main__':
    main()

何をしているのかの詳細はここがわかりやすい。

smach/Tutorials/Getting Started - ROS Wiki

4 . viewer の起動  

rosrun smach_viewer smach_viewer.py 状態遷移の状態確認

f:id:shun0612:20181029203322p:plain

linux 使用メモリをros topic としてpublish

使用メモリをros topic としてpublish

グラフでメモリ使用量がどうなっているか評価するときにbagの中にメモリの使用量も入れておこう考えた。

メモ

#!/usr/bin/env python
import rospy
import sys
import os
import commands

from std_msgs.msg import MultiArrayLayout
from std_msgs.msg import MultiArrayDimension
from geometry_msgs.msg import PoseStamped


if __name__ == '__main__':

    args = sys.argv

    pub = rospy.Publisher('memory', PoseStamped, queue_size=10)
    rospy.init_node('system_monitor', anonymous=True)
    r = rospy.Rate(10) 


    while not rospy.is_shutdown():
        msg = PoseStamped()
        msg.header.frame_id = "memory_swap"
        msg.header.stamp = rospy.Time.now()
        memory = commands.getoutput('free -m --si | grep -e Mem -e Swap | while read a b c d e f g; do echo -n "$b $c "; done | tr -d GB').split()
        #msg.pose.orientation.x,msg.pose.orientation.y,msg.pose.orientation.z, msg.pose.orientation.w = commands.getoutput("free -m --si | grep -e Mem -e Swap | while read a b c d e f g; do echo $b $c; done | tr -d GB")
        print memory
        msg.pose.orientation.x = float(memory[0])
        msg.pose.orientation.y = float(memory[1])
        msg.pose.orientation.z = float(memory[2])
        msg.pose.orientation.w = float(memory[3])

        pub.publish(msg)
        r.sleep()

だいぶ無理がある。

linux , bibtexで論文の管理を簡単にしたい

論文を書くときにリファレンスに時間をかけない。

論文を書いている時に、リファレンスは学会や論文の種類によってフォーマットが全然違う。毎回気を使いながら少しずつ直すのは手間である。 例えば in proceedings のところはイタリックだったり違ったり。。。 そんな時bibtexというものを知った。厳密には知っていたが、ネットなどを見ても使い方がうまく調べられず。疎遠になってしまっていた。 最低限使えるようになったので備忘録。

環境
ubuntu16.04
linux

bibtexの概要

基本的に論文の情報を一つのファイルにまとめて書いてあって、それを自由に引き出したりしている。
- hoge.bst 設定ファイル(各会議や雑誌が用意しているbibtexの設定ファイル
- huga.bib 自分が調べた論文
基本的には2つのファイルがあればできる。

  1. bibtexが使える環境準備
    基本的にはlatexmkでpdfを作れているのであれば、問題がないみたい.
    memo-methods-in-researching.hatenablog.com

  2. bst ファイルを手に入れる
    基本的には会議などのテンプレートを手に入れた時についてくる。 どんなファイルを用いているのかきちんと確認する。

  3. bib ファイルを作成する.
    ここには自分の読んだ論文の情報をbibtex方式で書く。 大体、google scholarでもIEEE exploreでもbibtex形式でcitation をダウンロードすることができる。 試しにここではreference.bibを作成

@article{toaru,
title={robot},
author={toaru gakusei and shun niijima},
journal={Journal of robot},
volume={22},
number={6},
pages={758-766},
year={2010}}
  • 自分のtexファイルでの書き方
toaru gakusei no bibouroku \cite{toaru}
\bibliographystyle{tADR}
\bibliography{reference}
  • 結果pdf f:id:shun0612:20181012233857p:plain

これは便利、論文の管理まで楽になる。

Linux で eps 編集

inkscape が使いやすそう

$sudo apt-get install inkscape

Times new romanフォントを使用する

Winsowsで使用しているフォントはデフォルトでは入っていない。

sudo apt-get install ttf-mscorefonts-installer

以上 使い心地はいずれ。。。

Ubntu16.04 でvim-rosを使用するときに必要なもの

vim でROSを開発している人はvim-rosがおすすめ

ROS用のおすすめVim設定&プラグイン - MyEnigma

vim-ros install error

vim-ros をubuntu16.04 で扱おうとするとpython3がデフォルトになっているのでうまく使えない。以下のコマンドで解決。

sudo apt-get update
sudo apt-get install vim-nox-py2