forked from jsk-ros-pkg/jsk_aerial_robot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Nov 11, 2023
1 parent
73a2649
commit a51dbd8
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
from apriltag_ros.msg import AprilTagDetectionArray | ||
from std_msgs.msg import Float64 | ||
|
||
class aprilBasedNav(): | ||
def __init__(self): | ||
rospy.init_node("subpub2") | ||
# define and initialize member veriants and functions(publisher, subscriber, others) | ||
self.detectionx = 0.0 | ||
self.pub = rospy.Publisher('detectionx', Float64, queue_size=1) | ||
self.sub = rospy.Subscriber('tag_detections', AprilTagDetectionArray, self.callback) | ||
self.rate = rospy.Rate(10) | ||
|
||
def callback(self,data): | ||
self.detectionx = data.detections[0].pose.pose.pose.position.x | ||
print(self.detectionx) | ||
|
||
# def subpub(): | ||
# global detectionx | ||
# rospy.init_node('subpub', anonymous = True) | ||
# sub = rospy.Subscriber('tag_detections', AprilTagDetectionArray, callback) | ||
# pub = rospy.Publisher('detectionx', Float64, queue_size=1) | ||
# rate = rospy.Rate(10) | ||
|
||
def main(self): | ||
while not rospy.is_shutdown(): | ||
self.pub.publish(self.detectionx) | ||
self.rate.sleep() | ||
# main process | ||
# pub.publish(detectionx) | ||
# rate.sleep() | ||
|
||
if __name__ == "__main__": | ||
try: | ||
april_base_nav = aprilBasedNav() | ||
april_base_nav.main() | ||
except rospy.ROSInterruptException: pass |