I am trying to store a callback data from ROS's topic called /scan in a properties (laser) of class that I created. I got an error like this: "No public field laser exists for class robotics.ros.Subscriber.Error in MobileRobot/Callback_Laser (line 14) obj.laser = [message.Ranges];Error in @(varargin)robot.Callback_Laser(varargin{:})Error in robotics.ros.internal.onNewMessageCallback (line 44) feval(callbackFcn, source, message, userData{:}); Warning: Error occurred while evaluating listener callback." Where is my mistake e how can I store a the callback data in a properties class? Next the code class. classdef MobileRobot < handle properties(Access = public) odom=[]; laser = []; end methods(Access = public) function obj = MobileRobot() % Constructor end function Callback_Laser(~, obj, message) % global laser % laser = [message.Ranges]; obj.laser = [message.Ranges]; end end end and the main code clear all;close all;clc; rosinit global rosMasterIp; rosMasterIp = 'http://192.168.0.113:11311'; global localhostIp; localhostIp = '192.168.0.113'; global robot; robot = MobileRobot(); set_pose = robotics.ros.Node('getLaser',rosMasterIp,'NodeHost' , localhostIp); subs = rossubscriber('/scan',@robot.Callback_Laser);
John Michell answered .
2025-11-20
function Callback_Laser(obj, src, message) obj.laser = [message.Ranges]; end