4 from geometry_msgs.msg
import QuaternionStamped
5 from nav_msgs.msg
import Odometry
6 from mavros_msgs.msg
import RCOut
7 from sensor_msgs.msg
import Joy
8 from sensor_msgs.msg
import NavSatFix
10 attitude_pub = rospy.Publisher(
'/sim/attitude', QuaternionStamped, queue_size = 1)
11 joy_pub = rospy.Publisher(
'/sim/actuators', Joy, queue_size = 1)
13 gps_pub = rospy.Publisher(
'/sim/gps_position', NavSatFix, queue_size = 1)
20 global raw_alt, alt_init, alt_corr, has_raw_alt
27 global raw_alt, alt_init, alt_corr, has_raw_alt
30 data.altitude += alt_corr
34 alt_corr = raw_alt - data.altitude
38 global raw_alt, has_raw_alt
40 raw_alt = data.altitude
44 q = QuaternionStamped()
45 q.header = data.header
46 q.quaternion = data.pose.pose.orientation
47 attitude_pub.publish(q)
59 FR_pwm = data.channels[0]
60 RL_pwm = data.channels[1]
61 FL_pwm = data.channels[2]
62 RR_pwm = data.channels[3]
63 pusher_pwm = data.channels[4]
64 aileron1_pwm = data.channels[5]
65 aileron2_pwm = data.channels[6]
66 elevator_pwm = data.channels[7]
81 FR_res = 15500*(FR_pwm - 900.0)/1100.0
82 RL_res = 15500*(RL_pwm - 900.0)/1100.0
83 FL_res = 15500*(FL_pwm - 900.0)/1100.0
84 RR_res = 15500*(RR_pwm - 900.0)/1100.0
85 aileron1_res = 70*(aileron1_pwm - 1500.0)/500.0
86 aileron2_res = 70*(aileron2_pwm - 1500.0)/500.0
87 elevator_res = 70*(elevator_pwm - 1500.0)/500.0
89 thrust_res = 15500*(pusher_pwm - 1000.0)/1000.0
91 joy.axes.append( round( FR_res, 1) )
92 joy.axes.append( round( RL_res, 1) )
93 joy.axes.append( round( FL_res, 1) )
94 joy.axes.append( round( RR_res, 1) )
95 joy.axes.append( round( aileron1_res, 1) )
96 joy.axes.append( round( aileron2_res, 1 ) )
97 joy.axes.append( round( elevator_res, 1) )
98 joy.axes.append( round( rudder_res, 1) )
99 joy.axes.append( round( thrust_res, 1) )
112 rospy.init_node(
'innosim_relay', anonymous=
True)
113 rospy.Subscriber(
'/mavros/global_position/local', Odometry, odom_callback)
114 rospy.Subscriber(
'/mavros/rc/out', RCOut, rc_callback)
115 rospy.Subscriber(
'/mavros/global_position/global', NavSatFix, global_gps_callback)
116 rospy.Subscriber(
'/mavros/global_position/raw/fix', NavSatFix, raw_gps_callback)
120 if __name__ ==
'__main__':
123 except rospy.ROSInterruptException:
def raw_gps_callback(data)
def global_gps_callback(data)