old_contents: #!/usr/bin/env python
  
  import rospy
  from sensor_msgs.msg import Joy
  from crazyflie.srv import UpdateParams
  from std_srvs.srv import Empty
  
  class Controller():
      def __init__(self, use_controller):
          self._buttons = None
          rospy.Subscriber("joy", Joy, self._joyChanged)
  
          rospy.wait_for_service('update_params')
          rospy.loginfo("found update_params service")
          self._update_params = rospy.ServiceProxy('update_params', UpdateParams)
  
          rospy.wait_for_service('emergency')
          rospy.loginfo("found emergency service")
          self._emergency = rospy.ServiceProxy('emergency', Empty)
  
          if use_controller:
              rospy.wait_for_service('land')
              rospy.loginfo("found land service")
              self._land = rospy.ServiceProxy('land', Empty)
  
              rospy.wait_for_service('takeoff')
              rospy.loginfo("found takeoff service")
              self._takeoff = rospy.ServiceProxy('takeoff', Empty)
          else:
              self._land = None
              self._takeoff = None
  
      def _joyChanged(self, data):
          for i in range(0, len(data.buttons)):
              if self._buttons == None or data.buttons[i] != self._buttons[i]:
                  if i == 0 and data.buttons[i] == 1 and self._land != None:
                      self._land()
                  if i == 1 and data.buttons[i] == 1:
                      self._emergency()
                  if i == 2 and data.buttons[i] == 1 and self._takeoff != None:
                      self._takeoff()
                  if i == 4 and data.buttons[i] == 1:
                      value = bool(int(rospy.get_param("ring/headlightEnable")))
                      print(value)
                      rospy.set_param("ring/headlightEnable", not value)
                      self._update_params(["ring/headlightEnable"])
                      print(not value)
  
          self._buttons = data.buttons
  
  if __name__ == '__main__':
      rospy.init_node('crazyflie_demo_controller', anonymous=True)
      use_controller = rospy.get_param("~use_crazyflie_controller")
      controller = Controller(use_controller)
      rospy.spin()
  
new_contents: #!/usr/bin/env python
  
  import rospy
  from sensor_msgs.msg import Joy
  from crazyflie.srv import UpdateParams
  from std_srvs.srv import Empty
  
  class Controller():
      def __init__(self, use_controller):
          rospy.wait_for_service('update_params')
          rospy.loginfo("found update_params service")
          self._update_params = rospy.ServiceProxy('update_params', UpdateParams)
  
          rospy.wait_for_service('emergency')
          rospy.loginfo("found emergency service")
          self._emergency = rospy.ServiceProxy('emergency', Empty)
  
          if use_controller:
              rospy.wait_for_service('land')
              rospy.loginfo("found land service")
              self._land = rospy.ServiceProxy('land', Empty)
  
              rospy.wait_for_service('takeoff')
              rospy.loginfo("found takeoff service")
              self._takeoff = rospy.ServiceProxy('takeoff', Empty)
          else:
              self._land = None
              self._takeoff = None
  
          # subscribe to the joystick at the end to make sure that all required
          # services were found
          self._buttons = None
          rospy.Subscriber("joy", Joy, self._joyChanged)
  
      def _joyChanged(self, data):
          for i in range(0, len(data.buttons)):
              if self._buttons == None or data.buttons[i] != self._buttons[i]:
                  if i == 0 and data.buttons[i] == 1 and self._land != None:
                      self._land()
                  if i == 1 and data.buttons[i] == 1:
                      self._emergency()
                  if i == 2 and data.buttons[i] == 1 and self._takeoff != None:
                      self._takeoff()
                  if i == 4 and data.buttons[i] == 1:
                      value = bool(int(rospy.get_param("ring/headlightEnable")))
                      print(value)
                      rospy.set_param("ring/headlightEnable", not value)
                      self._update_params(["ring/headlightEnable"])
                      print(not value)
  
          self._buttons = data.buttons
  
  if __name__ == '__main__':
      rospy.init_node('crazyflie_demo_controller', anonymous=True)
      use_controller = rospy.get_param("~use_crazyflie_controller", False)
      controller = Controller(use_controller)
      rospy.spin()
  
subject: Make use_controller optional (disabled by default)