Python geometry_msgs.msg.Twist() Examples
The following are 30
code examples of geometry_msgs.msg.Twist().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
geometry_msgs.msg
, or try the search function
.
Example #1
Source File: move_circle.py From ROS-Robotics-By-Example with MIT License | 10 votes |
def move_circle(): # Create a publisher which can "talk" to Turtlesim and tell it to move pub = rospy.Publisher('turtle1/cmd_vel', Twist, queue_size=1) # Create a Twist message and add linear x and angular z values move_cmd = Twist() move_cmd.linear.x = 1.0 move_cmd.angular.z = 1.0 # Save current time and set publish rate at 10 Hz now = rospy.Time.now() rate = rospy.Rate(10) # For the next 6 seconds publish cmd_vel move commands to Turtlesim while rospy.Time.now() < now + rospy.Duration.from_sec(6): pub.publish(move_cmd) rate.sleep()
Example #2
Source File: boat_rudder_vel_ctrl.py From usv_sim_lsa with Apache License 2.0 | 7 votes |
def __init__(self): rospy.init_node('usv_vel_ctrl', anonymous=False) self.rate = 10 r = rospy.Rate(self.rate) # 10hertz self.usv_vel = Odometry() self.usv_vel_ant = Odometry() self.target_vel = Twist() self.target_vel_ant = Twist() self.thruster_msg = JointState() self.rudder_msg = JointState() self.thruster_msg.header = Header() self.rudder_msg.header = Header() self.kp_lin = 80 self.ki_lin = 200 thruster_name = 'fwd' rudder_name = 'rudder_joint' self.I_ant_lin = 0 self.I_ant_ang = 0 self.lin_vel = 0 self.lin_vel_ang = 0 self.ang_vel = 0 self.kp_ang = 2 self.ki_ang = 4 self.rudder_max = 70 self.thruster_max = 30 self.pub_motor = rospy.Publisher('thruster_command', JointState, queue_size=10) self.pub_rudder = rospy.Publisher('joint_setpoint', JointState, queue_size=10) rospy.Subscriber("state", Odometry, self.get_usv_vel) rospy.Subscriber("cmd_vel", Twist, self.get_target_vel) while not rospy.is_shutdown(): self.pub_rudder.publish(self.rudder_ctrl_msg(self.ang_vel_ctrl(), rudder_name)) self.pub_motor.publish(self.thruster_ctrl_msg(self.lin_vel_ctrl(), thruster_name)) r.sleep()
Example #3
Source File: virtual_joystick.py From ROS-Programming-Building-Powerful-Robots with MIT License | 6 votes |
def pubTwist(self): ####################################################### # rospy.loginfo("publishing twist from (%0.3f,%0.3f)" %(self.x,self.y)) self.twist = Twist() self.twist.linear.x = (1-self.y) * (x_max - x_min) + x_min self.twist.linear.y = 0 self.twist.linear.z = 0 self.twist.angular.x = 0 self.twist.angular.y = 0 self.twist.angular.z = (1-self.x) * (r_max - r_min) + r_min if self.twist.linear.x > x_max: self.twist.linear.x = x_max if self.twist.linear.x < x_min: self.twist.linear.x = x_min if self.twist.angular.z > r_max: self.twist.angular.z = r_max if self.twist.angular.z < r_min: self.twist.angular.z = r_min self.pub_twist.publish( self.twist ) ########################################################################## ##########################################################################
Example #4
Source File: script.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def execute(self, inputs, outputs, gvm): turtle_name = inputs["turtle_name"] x = inputs["x_vel"] phi = inputs["phi_vel"] rate = rospy.Rate(10) position_vector = Vector3(x, 0, 0) rotation_vector = Vector3(0, 0, phi) twist_msg = Twist(position_vector, rotation_vector) self.logger.info("moving turtle {} {}".format(str(x), str(phi))) self.logger.info("publish twist to turtle {}".format(turtle_name)) turtle_vel_publisher = rospy.Publisher("/" + turtle_name + "/cmd_vel", Twist, queue_size=10, latch=True) turtle_vel_publisher.publish(twist_msg) rate.sleep() return 0
Example #5
Source File: script.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def set_velocity(x, phi, turtle_name, logger): position_vector = Vector3(x, 0, 0) rotation_vector = Vector3(0, 0, phi) twist_msg = Twist(position_vector, rotation_vector) try: logger.info("move_to_position: publish twist to turtle".format(turtle_name)) turtle_vel_publisher = rospy.Publisher("/" + turtle_name + "/cmd_vel", Twist, queue_size=10, latch=True) turtle_vel_publisher.publish(twist_msg) rate = rospy.Rate(10) rate.sleep() except rospy.ROSInterruptException as e: logger.error("Failed to send a velocity command to turtle {}: {}".format(turtle_name, str(e)))
Example #6
Source File: control.py From trajectory_tracking with MIT License | 6 votes |
def compute_control_actions(): global i controller.compute_control_actions(current_pose, current_twist, i) data_container['t'].append(i * DELTA_T) data_container['x'].append(current_pose.position.x) data_container['x_ref'].append(controller.x_ref_n) data_container['y'].append(current_pose.position.y) data_container['y_ref'].append(controller.y_ref_n) data_container['theta'].append(controller.theta_n) data_container['theta_ref'].append(controller.theta_ref_n) data_container['v_c'].append(controller.v_c_n) data_container['w_c'].append(controller.w_c_n) data_container['zeros'].append(0) twist = Twist() twist.linear.x = controller.v_c_n twist.angular.z = controller.w_c_n twist_publisher.publish(twist) i += 1
Example #7
Source File: mavros_control1.py From vision_to_mavros with GNU General Public License v3.0 | 6 votes |
def __init__(self): rospy.init_node("mav_control_node") rospy.Subscriber("/mavros/local_position/pose", PoseStamped, self.pose_callback) rospy.Subscriber("/mavros/rc/in", RCIn, self.rc_callback) self.cmd_pos_pub = rospy.Publisher("/mavros/setpoint_position/local", PoseStamped, queue_size=1) self.cmd_vel_pub = rospy.Publisher("/mavros/setpoint_velocity/cmd_vel_unstamped", Twist, queue_size=1) self.rc_override = rospy.Publisher("/mavros/rc/override", OverrideRCIn, queue_size=1) # mode 0 = STABILIZE # mode 4 = GUIDED # mode 9 = LAND self.mode_service = rospy.ServiceProxy('/mavros/set_mode', SetMode) self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool) self.takeoff_service = rospy.ServiceProxy('/mavros/cmd/takeoff', CommandTOL) self.rc = RCIn() self.pose = Pose() self.timestamp = rospy.Time()
Example #8
Source File: mavros_control1.py From vision_to_mavros with GNU General Public License v3.0 | 6 votes |
def set_vel(self, vx, vy, vz, avx=0, avy=0, avz=0): """ Send comand velocities. Must be in GUIDED mode. Assumes angular velocities are zero by default. """ cmd_vel = Twist() cmd_vel.linear.x = vx cmd_vel.linear.y = vy cmd_vel.linear.z = vz cmd_vel.angular.x = avx cmd_vel.angular.y = avy cmd_vel.angular.z = avz self.cmd_vel_pub.publish(cmd_vel)
Example #9
Source File: mavros_control2.py From vision_to_mavros with GNU General Public License v3.0 | 6 votes |
def __init__(self): rospy.init_node("mav_control_node") rospy.Subscriber("/mavros/local_position/pose", PoseStamped, self.pose_callback) rospy.Subscriber("/mavros/rc/in", RCIn, self.rc_callback) self.cmd_pos_pub = rospy.Publisher("/mavros/setpoint_position/local", PoseStamped, queue_size=1) self.cmd_vel_pub = rospy.Publisher("/mavros/setpoint_velocity/cmd_vel_unstamped", Twist, queue_size=1) self.rc_override = rospy.Publisher("/mavros/rc/override", OverrideRCIn, queue_size=1) # mode 0 = STABILIZE # mode 4 = GUIDED # mode 9 = LAND self.mode_service = rospy.ServiceProxy('/mavros/set_mode', SetMode) self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool) self.takeoff_service = rospy.ServiceProxy('/mavros/cmd/takeoff', CommandTOL) self.rc = RCIn() self.pose = Pose() self.timestamp = rospy.Time()
Example #10
Source File: mavros_control2.py From vision_to_mavros with GNU General Public License v3.0 | 6 votes |
def set_vel(self, vx, vy, vz, avx=0, avy=0, avz=0): """ Send comand velocities. Must be in GUIDED mode. Assumes angular velocities are zero by default. """ cmd_vel = Twist() cmd_vel.linear.x = vx cmd_vel.linear.y = vy cmd_vel.linear.z = vz cmd_vel.angular.x = avx cmd_vel.angular.y = avy cmd_vel.angular.z = avz self.cmd_vel_pub.publish(cmd_vel)
Example #11
Source File: turtlesim_joy.py From ROS-Robotics-By-Example with MIT License | 6 votes |
def tj_callback(data): # start publisher of cmd_vel to control Turtlesim pub = rospy.Publisher("turtle1/cmd_vel", Twist, queue_size=1) # Create Twist message & add linear x and angular z from left joystick twist = Twist() twist.linear.x = data.axes[1] twist.angular.z = data.axes[0] # record values to log file and screen rospy.loginfo("twist.linear: %f ; angular %f", twist.linear.x, twist.angular.z) # process joystick buttons if data.buttons[0] == 1: # green button on xbox controller move_circle() # publish cmd_vel move command to Turtlesim pub.publish(twist)
Example #12
Source File: virtual_joystick.py From ROS-Programming-Building-Powerful-Robots with MIT License | 6 votes |
def pubTwist(self): ####################################################### # rospy.loginfo("publishing twist from (%0.3f,%0.3f)" %(self.x,self.y)) self.twist = Twist() self.twist.linear.x = (1-self.y) * (x_max - x_min) + x_min self.twist.linear.y = 0 self.twist.linear.z = 0 self.twist.angular.x = 0 self.twist.angular.y = 0 self.twist.angular.z = (1-self.x) * (r_max - r_min) + r_min if self.twist.linear.x > x_max: self.twist.linear.x = x_max if self.twist.linear.x < x_min: self.twist.linear.x = x_min if self.twist.angular.z > r_max: self.twist.angular.z = r_max if self.twist.angular.z < r_min: self.twist.angular.z = r_min self.pub_twist.publish( self.twist ) ########################################################################## ##########################################################################
Example #13
Source File: racecar_joy.py From tianbot_racecar with GNU General Public License v3.0 | 6 votes |
def __init__(self): rospy.loginfo("Tianbot Racecar JoyTeleop Initializing...") self._twist = Twist() self._twist.linear.x = 1500 self._twist.angular.z = 90 self._deadman_pressed = False self._zero_twist_published = False self._cmd_vel_pub = rospy.Publisher('~/car/cmd_vel', Twist, queue_size=5) self._joy_sub = rospy.Subscriber('/joy', Joy, self.joy_callback) self._timer = rospy.Timer(rospy.Duration(0.05), self.joystick_controller) self._axis_throttle = 1 _joy_mode = rospy.get_param("~joy_mode", "D").lower() if _joy_mode == "d": self._axis_servo = 2 if _joy_mode == "x": self._axis_servo = 3 self._throttle_scale = rospy.get_param("~throttle_scale", 0.5) self._servo_scale = rospy.get_param("~servo_scale", 1)
Example #14
Source File: teleop_key.py From cozmo_driver with Apache License 2.0 | 6 votes |
def __init__(self): # setup CozmoTeleop.settings = termios.tcgetattr(sys.stdin) atexit.register(self.reset_terminal) # vars self.head_angle = STD_HEAD_ANGLE self.lift_height = STD_LIFT_HEIGHT # params self.lin_vel = rospy.get_param('~lin_vel', 0.2) self.ang_vel = rospy.get_param('~ang_vel', 1.5757) # pubs self._head_pub = rospy.Publisher('head_angle', Float64, queue_size=1) self._lift_pub = rospy.Publisher('lift_height', Float64, queue_size=1) self._cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)
Example #15
Source File: virtual_joystick.py From differential-drive with GNU General Public License v3.0 | 6 votes |
def pubTwist(self): ####################################################### # rospy.loginfo("publishing twist from (%0.3f,%0.3f)" %(self.x,self.y)) self.twist = Twist() self.twist.linear.x = (1-self.y) * (x_max - x_min) + x_min self.twist.linear.y = 0 self.twist.linear.z = 0 self.twist.angular.x = 0 self.twist.angular.y = 0 self.twist.angular.z = (1-self.x) * (r_max - r_min) + r_min if self.twist.linear.x > x_max: self.twist.linear.x = x_max if self.twist.linear.x < x_min: self.twist.linear.x = x_min if self.twist.angular.z > r_max: self.twist.angular.z = r_max if self.twist.angular.z < r_min: self.twist.angular.z = r_min self.pub_twist.publish( self.twist ) ########################################################################## ##########################################################################
Example #16
Source File: PR2.py From visual_dynamics with MIT License | 5 votes |
def set_twist(self, xya): vx, vy, omega = xya twist = gm.Twist() twist.linear.x = vx twist.linear.y = vy twist.angular.z = omega self.command_pub.publish(twist)
Example #17
Source File: core.py From pyrobot with MIT License | 5 votes |
def __init__(self, configs): """ The consturctor for Base class. :param configs: configurations for base :type configs: YACS CfgNode """ self.configs = configs self.ctrl_pub = rospy.Publisher( configs.BASE.ROSTOPIC_BASE_COMMAND, Twist, queue_size=1 )
Example #18
Source File: core.py From pyrobot with MIT License | 5 votes |
def stop(self): """ Stop the base """ msg = Twist() msg.linear.x = 0 msg.angular.z = 0 self.ctrl_pub.publish(msg)
Example #19
Source File: ros_env_cont_raw_scan_prep_wp.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_cmd_vel_(self, action): vel_msg = Twist() vel_msg.linear.x = action[0] vel_msg.angular.z = action[1] return vel_msg
Example #20
Source File: twist_to_motors.py From Learning-Robotics-using-Python-Second-Edition with MIT License | 5 votes |
def __init__(self): ############################################################# rospy.init_node("twist_to_motors") nodename = rospy.get_name() rospy.loginfo("%s started" % nodename) self.w = rospy.get_param("~base_width", 0.2) self.pub_lmotor = rospy.Publisher('lwheel_vtarget', Float32,queue_size=10) self.pub_rmotor = rospy.Publisher('rwheel_vtarget', Float32,queue_size=10) rospy.Subscriber('cmd_vel', Twist, self.twistCallback) self.rate = rospy.get_param("~rate", 50) self.timeout_ticks = rospy.get_param("~timeout_ticks", 2) self.left = 0 self.right = 0 #############################################################
Example #21
Source File: PR2.py From visual_dynamics with MIT License | 5 votes |
def __init__(self, pr2): self.pr2 = pr2 self.action_client = actionlib.SimpleActionClient('move_base', mbm.MoveBaseAction) self.command_pub = rospy.Publisher('base_controller/command', gm.Twist) self.traj_pub = rospy.Publisher("base_traj_controller/command", tm.JointTrajectory) self.vel_limits = [.2, .2, .3] self.acc_limits = [2, 2, 2] # note: I didn't think these thru self.n_joints = 3
Example #22
Source File: publish_twist_state.py From generic_flexbe_states with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, topic): """Constructor""" super(PublishTwistState, self).__init__(outcomes=['done'], input_keys=['twist']) self._topic = topic self._pub = ProxyPublisher({self._topic: Twist})
Example #23
Source File: task_generator.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __stop_robot(self): """ Stops robot. """ # self.__agent_action_pub.publish(Twist()) self.__cmd_vel_pub.publish(Twist()) return
Example #24
Source File: ros_env_disc_img_vel.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_cmd_vel_(self, action): encoded_action = self.__encode_action(action) vel_msg = Twist() vel_msg.linear.x = encoded_action[0] vel_msg.angular.z = encoded_action[1] return vel_msg
Example #25
Source File: ros_env.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def reset(self): """ Resetting simulation environment. That means, the robots position and goal are set randomly. Furthermore obstacles are spawned on that path. :return: initial observation of episode """ if self.MODE != "train" and self.MODE != "train_demo" and self.MODE != "eval": return self.get_observation_() # resetting task self.__set_task() self.__agent_action_pub.publish(Twist()) # waiting for planner to be ready for its first action begin = time.time() while not self.__trigger and not rospy.is_shutdown(): if (time.time() - begin) > 20.0: rospy.logerr("%s, reset(): Timeout while waiting for local planner." % (self.NS)) self.__set_task() begin = time.time() time.sleep(0.001) self.__trigger = False # reseting internal state values self.__num_iterations = 0 # Initializing state variables self.__task_generator.take_sim_step() self.__collect_state() self.__reward_cont.reset(self.wp_.points) return self.get_observation_()
Example #26
Source File: ros_env_disc_raw_scan_prep_wp.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_cmd_vel_(self, action): encoded_action = self.__encode_action(action) vel_msg = Twist() vel_msg.linear.x = encoded_action[0] vel_msg.angular.z = encoded_action[1] return vel_msg
Example #27
Source File: ros_env_disc_img.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_cmd_vel_(self, action): encoded_action = self.__encode_action(action) vel_msg = Twist() vel_msg.linear.x = encoded_action[0] vel_msg.angular.z = encoded_action[1] return vel_msg
Example #28
Source File: ros_env_cont_img.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_cmd_vel_(self, action): vel_msg = Twist() vel_msg.linear.x = action[0] vel_msg.angular.z = action[1] return vel_msg
Example #29
Source File: ros_env_cont_raw_data.py From drl_local_planner_ros_stable_baselines with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_cmd_vel_(self, action): vel_msg = Twist() vel_msg.linear.x = action[0] vel_msg.angular.z = action[1] return vel_msg
Example #30
Source File: virtual_joystick.py From differential-drive with GNU General Public License v3.0 | 5 votes |
def __init__(self): ##################################################################### super(MainWindow, self).__init__() self.timer_rate = rospy.get_param('~publish_rate', 50) self.pub_twist = rospy.Publisher('twist', Twist, queue_size=10) self.initUI() #####################################################################