4 from sensor_msgs.msg
import NavSatFix
5 from geometry_msgs.msg
import QuaternionStamped
6 from sensor_msgs.msg
import Joy
7 from pyquaternion
import Quaternion
9 FRD_FLU = Quaternion(w=0, x=1, y=0, z=0)
10 NED_TO_ENU = Quaternion(w=0, x=0.70711, y=0.70711, z=0)
14 self.
attitude_pub = rospy.Publisher(
'/sim/attitude', QuaternionStamped, queue_size = 1)
15 self.
joy_pub = rospy.Publisher(
'/sim/actuators', Joy, queue_size = 1)
16 self.
gps_pub = rospy.Publisher(
'/sim/gps_position', NavSatFix, queue_size = 1)
18 rospy.Subscriber(
'/uav/gps_point', NavSatFix, self.
gps_callback)
24 self.
joy.axes = [0] * 9
27 self.
gps_msg.header.stamp = in_msg.header.stamp
28 self.
gps_msg.latitude = in_msg.latitude * 1e-08
29 self.
gps_msg.longitude = in_msg.longitude * 1e-08
30 self.
gps_msg.altitude = in_msg.altitude * 1e-03 + 6.5
37 q = Quaternion(w=msg.quaternion.w,
42 q = NED_TO_ENU * q * FRD_FLU
44 msg.quaternion.w = q.w
45 msg.quaternion.x = q.x
46 msg.quaternion.y = q.y
47 msg.quaternion.z = q.z
53 if len(actuators.axes) < 4:
54 rospy.logerr_throttle(5,
"InnosimUavcanBridge: wrong actuators msg len(axes) < 4")
56 elif len(actuators.axes) != 8:
57 rospy.logwarn_throttle(5,
"InnosimUavcanBridge: wrong airframe. Let it be MC.")
59 rospy.logerr_throttle(5,
"InnosimUavcanBridge: wrong actuators msg. There is no axes")
74 mixer = [0] * min(len(MIXER_MIN_MAX), len(actuators.axes))
75 for idx
in range(len(mixer)):
76 mixer[idx] = max(MIXER_MIN_MAX[idx][0], min(actuators.axes[idx], MIXER_MIN_MAX[idx][1]))
78 mixer[4] = (mixer[4] - 0.5) * 2
93 for idx
in range(min(4, len(mixer))):
94 self.
joy.axes[idx] = mixer[idx] * SIM_MAX_VALUES[idx]
96 self.
joy.axes[4] = mixer[4] * SIM_MAX_VALUES[4]
97 self.
joy.axes[5] = -mixer[4] * SIM_MAX_VALUES[5]
98 self.
joy.axes[6] = mixer[5] * SIM_MAX_VALUES[6]
99 self.
joy.axes[7] = mixer[6] * SIM_MAX_VALUES[7]
100 self.
joy.axes[8] = mixer[7] * SIM_MAX_VALUES[8]
105 if __name__ ==
'__main__':
107 rospy.init_node(
'innosim_relay', anonymous=
True)
110 except rospy.ROSInterruptException:
def attitude_callback(self, msg)
def gps_callback(self, in_msg)
def actuators_callback(self, actuators)