20 import tf.transformations
as trans
21 from PIDRegulator
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
32 print(
'PositionControllerNode: initializing node')
50 self.
pub_cmd_vel = rospy.Publisher(
'cmd_vel', geometry_msgs.Twist, queue_size=10)
54 """Handle updated set pose callback.""" 57 q = msg.pose.orientation
58 self.
pos_des = numpy.array([p.x, p.y, p.z])
59 self.
quat_des = numpy.array([q.x, q.y, q.z, q.w])
62 """Handle updated measured velocity callback.""" 66 p = msg.pose.pose.position
67 q = msg.pose.pose.orientation
68 p = numpy.array([p.x, p.y, p.z])
69 q = numpy.array([q.x, q.y, q.z, q.w])
78 t = msg.header.stamp.to_sec()
81 e_pos = trans.quaternion_matrix(q).transpose()[0:3,0:3].dot(self.
pos_des - p)
83 vz = self.pid_depth.regulate(e_pos[2], t)
84 vx = self.pid_forward.regulate(numpy.linalg.norm(e_pos[0:2]), t)
85 wx = self.pid_heading.regulate(numpy.arctan2(), t)
87 v_linear = numpy.array([vx, 0, vz])
88 v_angular = numpy.array([0, 0, wz])
91 cmd_vel = geometry_msgs.Twist()
92 cmd_vel.linear = geometry_msgs.Vector3(*v_linear)
93 cmd_vel.angular = geometry_msgs.Vector3(*v_angular)
95 self.pub_cmd_vel.publish(cmd_vel)
98 """Handle updated configuration values.""" 100 self.
pid_forward = PIDRegulator(config[
'forward_p'], config[
'forward_i'], config[
'forward_d'], config[
'forward_sat'])
101 self.
pid_depth = PIDRegulator(config[
'depth_p'], config[
'depth_i'], config[
'depth_d'], config[
'depth_sat'])
102 self.
pid_heading = PIDRegulator(config[
'heading_p'], config[
'heading_i'], config[
'heading_d'], config[
'heading_sat'])
109 if __name__ ==
'__main__':
110 print(
'starting PositionControl.py')
111 rospy.init_node(
'position_control')
116 except rospy.ROSInterruptException:
117 print(
'caught exception')
def config_callback(self, config, level)
def odometry_callback(self, msg)
def cmd_pose_callback(self, msg)