Hi,

I've launched the launch file and executed the command:

rostopic list | grep move_drone_square

However I do not see any output.

Please advise!

Thanks

asked 14 Mar, 09:33

maxxy.tjr's gravatar image

maxxy.tjr
01
accept rate: 0%


Hello @maxxy.tjr,

Let's divide the command rostopic list | grep move_drone_square into two parts:

  • rostopic list - List all topics in a ROS environment
  • grep move_drone_square - Show only the line of the shell that contains the expression move_drone_square

So.. If you are publishing to a topic and you can't see it in the terminal, you have to make sure the name of the topic you are publishing to.

Can you share your code here?

Regards

permanent link

answered 15 Mar, 22:17

marcoarruda's gravatar image

marcoarruda ♦♦
1764
accept rate: 18%

import rospy
import actionlib
from actionlib.msg import TestFeedback, TestResult, TestAction
import time

from geometry_msgs import Twist
from std_msgs import Empty

class MoveDroneSq(object):

# create messages that are used to publish feedback and result
_feedback = TestFeedback()
_result = TestResult()
# constructor
def __init__(self):

    self._as = actionlib.SimpleActionServer(
        "move_drone_sq", TestAction, self.goal_callback, False)
    self._as.start()
    self.ctrl_c = False
    self.rate = rospy.Rate(10)

def publish_once_in_cmd_vel(self, cmd):
    while not self.ctrl_c:
        connections = self._pub_cmd_vel.get_num_connections()
        if connections > 0:
            self._pub_cmd_vel.publish(cmd)
            rospy.loginfo("Publishing in cmd_vel...")
            break
        else:
            self.rate.sleep()

def move_forward(self):
    rospy.loginfo("Moving forward...")
    self._move.linear.x = 1.0
    self._move.angular.z = 0.0
    self.publish_once_in_cmd_vel(self._move)

def rotate(self):
    rospy.loginfo("rotating...")
    self._move.linear.x = 0.0
    self._move.angular.z = 1.0
    self.publish_once_in_cmd_vel(self._move)

def stop_drone(self):
    rospy.loginfo("Stopping drone...")
    self._move.linear.x = 0.0
    self._move.angular.z = 0.0
    self.publish_once_in_cmd_vel(self._move)

# this callback is called when the action server is called by the action client
def goal_callback(self, goal):

    # define the publishers
    self._pub_cmd_vel = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
    self._move = Twist()

    self._pub_takeoff = rospy.Publisher(
        '/drone/takeoff', Empty, queue_size=1)
    self._takeoff = Empty()

    self._pub_land = rospy.Publisher('/drone/land', Empty, queue_size=1)
    self._land = Empty()

    # helper variables
    rate = rospy.Rate(1)
    success = True

    self._result.totalSeconds = 0

    # launch the drone
    for i in range(0, 3):
        rospy.loginfo("Taking off...")
        self._pub_takeoff.publish(self._takeoff)
        time.sleep(1)

    # define the time to move in each side of the square (which is taken from the goal) and the time to turn
    sideSeconds = goal.goal
    turnSeconds = 2

    for i in range(0, 4):
        if self._as.is_preempt_requested():
            rospy.loginfo("Goal has been cancelled.")
            self._as.set_preempted()
            success = False
            break

        self.move_forward()
        time.sleep(sideSeconds)
        self.rotate()
        time.sleep(turnSeconds)

        # build and publish the feedback message
        self._feedback.feedback = i
        self._as.publish_feedback(self._feedback)
        rate.sleep()

        if success:
            rospy.loginfo("Succeeded in moving the quadcopter in a square")
            self._result.result = (sideSeconds*4) + (turnSeconds*4)
            # send the result
            self._as.set_succeeded(self._result)

    # successful or not, land the drone
    self.stop_drone()

    for i in range(0, 3):
        self._pub_land.publish(self._land)
        rospy.loginfo("Landing...")
        time.sleep(1)

if __name__ == "__main__":
    rospy.init_node("move_drone_square")
    MoveDroneSq()
    rospy.spin()

So this is my code... but I can't seem to figure out where I went wrong. I defined "move_drone_square" from under the "name" argument in my launch file

permanent link

answered 16 Mar, 03:28

maxxy.tjr's gravatar image

maxxy.tjr
01
accept rate: 0%

Hello,

As my mate Marco said, the command rostopic list | grep move_drone_square looks, between all your topics, any that contains the expression move_drone_square. From the code you've posted right above, it looks like you don't have any topic with that expression. You do have named your node move_drone_square, but that's not a topic. For nodes, the command used is rosnode list. In your case, and from the code posted, it looks like the namespace of your Action Server is move_drone_sq. Hence, the command you should use if you want to look for that is rostopic list | grep move_drone_sq.

Hope this helps you,

permanent link

answered 18 Mar, 19:48

albertoezquerro%40gmail.com's gravatar image

albertoezque... ♦♦
30
accept rate: 16%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×1

question asked: 14 Mar, 09:33

question was seen: 153 times

last updated: 18 Mar, 19:48

Related questions

powered by OSQA