Main Content

setVelocity

Send linear and angular velocities to TurtleBot

Add-On Required: This feature requires the ROS Toolbox Support Package for TurtleBot-Based Robots add-on.

Description

setVelocity(tbot,linearVel) sends a linear velocity command to the TurtleBot® connected through the interface object, tbot. The function assumes an angular velocity of zero. It sends a single velocity command, and the robot moves for a fixed time, depending on the hardware.

setVelocity(tbot,linearVel,angularVel) sends a linear and angular velocity command to the TurtleBot.

example

setVelocity(tbot,twistMsg) sends to the TurtleBot a Twist ROS message containing linear and angular velocity commands.

setVelocity(___,'Time',timeperiod) sends a velocity command repeatedly during the specified timeperiod in seconds. The publish frequency is 20 Hz. After the elapsed time, the function sends a velocity of zero. You can specify input arguments from any of the previous syntaxes.

Examples

collapse all

Connect to the TurtleBot robot. Change '192.168.1.1' to the IP address of the robot.

tbot = turtlebot('192.168.1.1');

Send a velocity command of 0.5 m/s and 0.1 rad/s.

setVelocity(tbot,0.5,0.1)

Input Arguments

collapse all

TurtleBot interface object, specified as a turtlebot object. The object contains properties for activating subscribers and accessing topic names relevant to the TurtleBot. The properties contain the topic name and active status of different subscribers for the TurtleBot. When you create the object with turtlebot, the properties available are:

tbot = turtlebot
tbot = 

  turtlebot with properties:

           Velocity: [1x1 struct]
         ColorImage: [1x1 struct]
          GrayImage: [1x1 struct]
         DepthImage: [1x1 struct]
         PointCloud: [1x1 struct]
          LaserScan: [1x1 struct]
           Odometry: [1x1 struct]
      OdometryReset: [1x1 struct]
                IMU: [1x1 struct]
    TransformFrames: {0x1 cell}
         TopicNames: {3x1 cell}

For properties with relevant ROS data messages, you can view the topic name and a subscriber’s active status. A specific subscriber is active for the given TopicName if Active equals 1.

tbot.Velocity
ans = 

    TopicName: '/mobile_base/commands/velocity'
       Active: 1

Linear velocity command, specified as a scalar in meters per second. The function sends only a single velocity command, and the robot moves for a fixed time, depending on the hardware.

Angular velocity command, specified as a scalar in radians per second. The function sends only a single velocity command, and the robot moves for a fixed time, depending on the hardware.

'geometry_msgs/Twist' ROS message containing linear and angular velocity commands, specified as a Twist object handle. To create a Twist object, use rosmessage.

Time period during which to send commands, specified as a scalar in seconds. The commands are published at frequency of 20 Hz. A velocity of zero is sent after the elapsed time.

Version History

Introduced in R2016a