getLaserScan

Get laser scan sensor readings from TurtleBot

Syntax

scan = getLaserScan(tbot)
[scan,scanMsg] = getLaserScan(tbot)
[___] = getLaserScan(tbot,timeout)

Description

example

scan = getLaserScan(tbot) waits for the next published laser scan message from the TurtleBot® connected through the interface object, tbot, and returns the laser scan. If no message is received in five seconds, the function displays an error.

[scan,scanMsg] = getLaserScan(tbot) also returns the received ROS laser scan message.

[___] = getLaserScan(tbot,timeout) waits for the next laser scan for timeout seconds. If no new message is received in that time, the function displays an error. A timeout of zero returns the latest received message without waiting. If no message has been received, the function returns an empty matrix for scan and an empty message for scanMsg, if specified.

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');

Get the latest laser scan from the TurtleBot.

scan = getLaserScan(tbot);

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

tbot = turtlebot('192.168.1.1');

Get the latest laser scan and message from the TurtleBot.

[scan,scanMsg] = getLaserScan(tbot);

Read laser scan in Cartesian coordinates. Laser scans are usually given in ranges and angles instead of xy-coordinates.

cart = readCartesian(scan);

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

tbot = turtlebot('192.168.1.1');

Get the latest laser scan and message from the TurtleBot.

[scan,scanMsg] = getLaserScan(tbot);

Plot the laser scan using plot.

plot(scanMsg)

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

Timeout for receiving an image, specified as a scalar in seconds. The function returns an error after timeout seconds. If timeout equals zero, the function returns the latest image. If the TurtleBot has no latest message, the function returns a blank image and blank image message.

Output Arguments

collapse all

Laser scan reading, returned as a structure containing these fields:

  • Ranges – A column vector containing the range distance readings in meters.

  • Angles – A column vector of scan angles at which Ranges were measured. Positive angles are measured counterclockwise from the x-axis in radians.

Ranges and Angles vectors always have the same length.

'sensor_msgs/LaserScan' ROS laser scan message, returned as a LaserScan object handle.

Introduced in R2016a