How to launch a drone

I am trying to launch the drone, but the drone won’t takeoff. Below is the code I am using

#! /usr/bin/env python

import rospy

import time

from std_msgs.msg import Empty

time.sleep(1)

print(“start”)

rospy.init_node(‘drone’)

takeoff = rospy.Publisher(’/drone/takeoff’, Empty, queue_size=1)

takeoff_msg = Empty() #Create the message to takeoff the drone

takeoff.publish(takeoff_msg)

time.sleep(3)

print(“end”)

rate= rospy.Rate(1)

Why is it not working

Hi @mccannm,

A few things you can try, these are generally good troubleshooting options:

  1. in a seperate Terminal, echo the topic you are publishing to. So here this would be:
    rostopic echo /drone/takeoff
    This way you can check and see, whether it is successfully being published.

  2. In general you can investigate topics, services and nodes by using these commands:
    rostopic list
    rosnode list
    rosservice list
    rostopic info /drone/takeoff (or any other topic, works for rosnode and rosservice too)

Two additional things you might want to keep in mind.

  • When working with simulations, it is better to use rospy.sleep(1) instead of time.sleep(1). Because usually you want to use the simulation time and not the computer time. The simulation might only run at half real time speed, or 5x as fast. And most importantly, that factor may change. So always use rospy.sleep or rospy.Rate(10).sleep() for timing your simulation code

  • the rate= rospy.Rate(1) at the end of your code does not do anything. You are simply defining a rospy rate. Check this link for what it does exactly:
    https://answers.ros.org/question/264812/explanation-of-rospyrate/

Finally, please use the </> format option on your pasted code, so it is easier to read :slight_smile:

I checked the course, I think your problem stems from not carefully reading the start of exercise 5.2
You have to start the action server in webshell #1 and leave it running.