19 from dynamic_reconfigure.server
import Server
20 import geometry_msgs.msg
as geometry_msgs
21 from nav_msgs.msg
import Odometry
22 import tf.transformations
as trans
23 from rospy.numpy_msg
import numpy_msg
26 from PID
import PIDRegulator
27 from uuv_control_cascaded_pid.cfg
import VelocityControlConfig
32 print(
'VelocityControllerNode: initializing node')
46 self.
pub_cmd_accel = rospy.Publisher(
'cmd_accel', geometry_msgs.Accel, queue_size=10)
50 """Handle updated set velocity callback.""" 58 """Handle updated measured velocity callback.""" 62 linear = msg.twist.twist.linear
63 angular = msg.twist.twist.angular
64 v_linear = numpy.array([linear.x, linear.y, linear.z])
65 v_angular = numpy.array([angular.x, angular.y, angular.z])
67 if self.
config[
'odom_vel_in_world']:
71 xyzw_array =
lambda o: numpy.array([o.x, o.y, o.z, o.w])
72 q_wb = xyzw_array(msg.pose.pose.orientation)
73 R_bw = trans.quaternion_matrix(q_wb)[0:3, 0:3].transpose()
75 v_linear = R_bw.dot(v_linear)
76 v_angular = R_bw.dot(v_angular)
79 t = msg.header.stamp.to_sec()
83 a_linear = self.pid_linear.regulate(e_v_linear, t)
84 a_angular = self.pid_angular.regulate(e_v_angular, t)
87 cmd_accel = geometry_msgs.Accel()
88 cmd_accel.linear = geometry_msgs.Vector3(*a_linear)
89 cmd_accel.angular = geometry_msgs.Vector3(*a_angular)
90 self.pub_cmd_accel.publish(cmd_accel)
93 """Handle updated configuration values.""" 95 self.
pid_linear = PIDRegulator(config[
'linear_p'], config[
'linear_i'], config[
'linear_d'], config[
'linear_sat'])
96 self.
pid_angular = PIDRegulator(config[
'angular_p'], config[
'angular_i'], config[
'angular_d'], config[
'angular_sat'])
103 if __name__ ==
'__main__':
104 print(
'starting VelocityControl.py')
105 rospy.init_node(
'velocity_control')
110 except rospy.ROSInterruptException:
111 print(
'caught exception')
def odometry_callback(self, msg)
def cmd_vel_callback(self, msg)
def config_callback(self, config, level)