20 import tf.transformations
as trans
21 from PID
import PIDRegulator
23 from dynamic_reconfigure.server
import Server
24 from uuv_control_cascaded_pid.cfg
import PositionControlConfig
25 import geometry_msgs.msg
as geometry_msgs
26 from nav_msgs.msg
import Odometry
27 from rospy.numpy_msg
import numpy_msg
31 print(
'PositionControllerNode: initializing node')
47 self.
pub_cmd_vel = rospy.Publisher(
'cmd_vel', geometry_msgs.Twist, queue_size=10)
51 """Handle updated set pose callback.""" 54 q = msg.pose.orientation
55 self.
pos_des = numpy.array([p.x, p.y, p.z])
56 self.
quat_des = numpy.array([q.x, q.y, q.z, q.w])
59 """Handle updated measured velocity callback.""" 63 p = msg.pose.pose.position
64 q = msg.pose.pose.orientation
65 p = numpy.array([p.x, p.y, p.z])
66 q = numpy.array([q.x, q.y, q.z, q.w])
75 t = msg.header.stamp.to_sec()
79 e_pos_body = trans.quaternion_matrix(q).transpose()[0:3,0:3].dot(e_pos_world)
82 e_rot_quat = trans.quaternion_multiply(trans.quaternion_conjugate(q), self.
quat_des)
84 if numpy.linalg.norm(e_pos_world[0:2]) > 5.0:
87 heading = math.atan2(e_pos_world[1],e_pos_world[0])
88 quat_des = numpy.array([0, 0, math.sin(0.5*heading), math.cos(0.5*heading)])
89 e_rot_quat = trans.quaternion_multiply(trans.quaternion_conjugate(q), quat_des)
92 e_rot = numpy.array(trans.euler_from_quaternion(e_rot_quat))
94 v_linear = self.pid_pos.regulate(e_pos_body, t)
95 v_angular = self.pid_rot.regulate(e_rot, t)
98 cmd_vel = geometry_msgs.Twist()
99 cmd_vel.linear = geometry_msgs.Vector3(*v_linear)
100 cmd_vel.angular = geometry_msgs.Vector3(*v_angular)
101 self.pub_cmd_vel.publish(cmd_vel)
104 """Handle updated configuration values.""" 106 self.
pid_pos = PIDRegulator(config[
'pos_p'], config[
'pos_i'], config[
'pos_d'], config[
'pos_sat'])
107 self.
pid_rot = PIDRegulator(config[
'rot_p'], config[
'rot_i'], config[
'rot_d'], config[
'rot_sat'])
114 if __name__ ==
'__main__':
115 print(
'starting PositionControl.py')
116 rospy.init_node(
'position_control')
121 except rospy.ROSInterruptException:
122 print(
'caught exception')
def config_callback(self, config, level)
def cmd_pose_callback(self, msg)
def odometry_callback(self, msg)