Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ros12p.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# 必要なpackageのimport
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっと古い書き方ですが2行目には
# -*- coding: utf-8 -*-
を入れておくと良いです
http://osksn2.hep.sci.osaka-u.ac.jp/~taku/osx/python/encoding.html

import rospy
from opencv_apps.msg import RotatedRectStamped
from image_view2.msg import ImageMarker2
from geometry_msgs.msg import Point

def cb(msg):
print msg.rect#msgのrectの表示
marker=ImageMarker2()#markerの定義
marker.type=0#markerを円にする。 ImageMarker2においてint32 type # CIRCLE/LINE_STRIP/etc.,byte CIRCLE=0
marker.position=Point(msg.rect.center.x,msg.rect.center.y,0) #ImageMarker2においてgeometry_msgs/Point position # used for CIRCLE/TEXT, 2D in pixel-coords.マーカーの位置を、msg.rectの中心に設定する。
pub.publish(marker)#markerを送信する

rospy.init_node('client')#nodeの名前(これによりMasterと通信できるようになる)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このインデント間違えている気がします
せっかくなのでノード名はプログラムを表すものにしてみましょう

rospy.Subscriber('/camshift/track_box',RotatedRectStamped,cb)#RotatedRectStamped型のメッセージを、'/camshift/track_box'というtopicからうけとり、cbを受け取ったメッセージを第一引数とするコールバック関数として用いる。
pub=rospy.Publisher('/image_marker',ImageMarker2)#'/image_marker'というtopicにImageMarker2型のメッセージを送信する
rospy.spin()#シャットダウンされるまでノードをexitさせない