8 from geometry_msgs.msg
import PoseStamped
10 from mavros_msgs.srv
import CommandBool
11 from mavros_msgs.srv
import CommandBoolRequest
13 from mavros_msgs.srv
import SetMode
14 from mavros_msgs.srv
import SetModeRequest
16 from mavros_msgs.msg
import State
18 current_state = State()
21 scr.addstr(posx, posy, string)
27 addstrln(scr,
"right arrow: turn right")
28 addstrln(scr,
"left arrow: turn left")
30 addstrln(scr,
"down arrow: downward")
34 scr.addstr(0, 0,
"w: forward")
40 msg.header.stamp = rospy.Time.now()
41 msg.pose.position.x += 0.1
45 msg.header.stamp = rospy.Time.now()
46 msg.pose.position.y += 0.1
50 msg.header.stamp = rospy.Time.now()
51 msg.pose.position.x -= 0.1
55 msg.header.stamp = rospy.Time.now()
56 msg.pose.position.y -= 0.1
60 msg.header.stamp = rospy.Time.now()
61 msg.pose.orientation.z = math.sin(0.5)
62 msg.pose.orientation.w = math.cos(0.5)
66 msg.header.stamp = rospy.Time.now()
67 msg.pose.position.z += 0.1
71 msg.header.stamp = rospy.Time.now()
72 msg.pose.orientation.z = math.sin(-0.5)
73 msg.pose.orientation.w = math.cos(-0.5)
77 msg.header.stamp = rospy.Time.now()
78 msg.pose.position.z -= 0.1
89 rospy.init_node(
"px4_teleop_key_pub", anonymous=
True)
90 rospy.loginfo(
"Node Initialized")
92 state_sub = rospy.Subscriber(
"mavros/state", State, state_cb, queue_size=10)
93 pos_teleop_pub = rospy.Publisher(
"mavros/setpoint_position/local", PoseStamped, queue_size=10)
95 arming_client = rospy.ServiceProxy(
"mavros/cmd/arming", CommandBool)
96 set_mode_client = rospy.ServiceProxy(
"mavros/set_mode", SetMode)
97 rospy.loginfo(
"Subscriber, Publisher and Service Clients are initilized")
99 rate = rospy.Rate(20.0)
101 while not rospy.is_shutdown()
and current_state.connected:
104 pos_teleop_msg = PoseStamped()
105 pos_teleop_msg.header.stamp = rospy.Time.now()
106 pos_teleop_msg.pose.position.x = 0.
107 pos_teleop_msg.pose.position.y = 0.
108 pos_teleop_msg.pose.position.z = 2.0
111 pos_teleop_pub.publish(pos_teleop_msg)
114 set_mode_req = SetModeRequest()
115 set_mode_req.custom_mode =
"OFFBOARD" 117 arm_cmd_req = CommandBoolRequest()
118 arm_cmd_req.value =
True 120 while not set_mode_client(set_mode_req).success:
123 rospy.loginfo(
"Offboard enabled")
125 while not arming_client(arm_cmd_req).success:
128 rospy.loginfo(
"Vehicle armed")
130 pos_teleop_pub.publish(pos_teleop_msg)
133 stdscr = curses.initscr()
139 while not rospy.is_shutdown():
140 if not current_state.mode==
"OFFBOARD":
141 set_mode_client(set_mode_req)
152 if __name__==
"__main__":
155 except rospy.ROSInterruptException:
def addstrln(scr, string, posx=0, posy=0)
def publish_pos(pub, msg, key)