The setData does method exist, but it is expecting a “org.jboss.netty.buffer.DuplicatedChannelBuffer” object as its argument. The easiest way to set the array is to use the getData method to return the object of the correct type, then set the relevant fields, and reuse the modified object as argument in setData.
The problem, of course, is that you have to know how to set the “array” data in the org.jboss.netty.buffer.DuplicatedChannelBuffer object. See http://docs.jboss.org/netty/3.2/api/org/jboss/netty/buffer/DuplicatedChannelBuffer.html on how to accomplish this. For demonstration purposes, I will use the setByte method
Try this:
roscore = rosmatlab.roscore(11311);
node = rosmatlab.node('NODE',roscore.RosMasterUri);
msg_im_pub = rosmatlab.message('sensor_msgs/Image', node);
imageData = msg_im_pub.getData()
imgCol = [0:127,0:127]'
for i = 1:numel(imgCol)
imageData.setByte(int32(i-1),int32(imgCol(i)))
end
msg_im_pub.setData(imageData)
msg_im_pub.getData().array %notice the modified array
Hope this helps.
Best regards,
Gareth
PS - this would be also a good candidate to post on MATLAB Answers:)
http://www.mathworks.nl/matlabcentral/answers/
--
You received this message because you are subscribed to the Google Groups "ros-sig-matlab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-matla...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
roscore = rosmatlab.roscore(11311);
node = rosmatlab.node('NODE',roscore.RosMasterUri);
publisher = rosmatlab.publisher('/matlab_image','sensor_msgs/Image',node);
msg_im_pub = rosmatlab.message('sensor_msgs/Image', node);
% Read some image here
image = imread('example_image.jpg');
[height,width,channels] = size(image);
image = permute(image,[3 2 1]); % Flip dimensions
image = image(:); % Vectorize
% Populate image message
msg_im_pub.setStep(width*channels);
msg_im_pub.setWidth(width);
msg_im_pub.setHeight(height);
msg_im_pub.setEncoding('rgb8'); % RGB image
msg_im_pub.setIsBigendian(false);
% Create java buffer to save the image array
messageBuffer = org.ros.internal.message.MessageBuffers.dynamicBuffer();
stream = org.jboss.netty.buffer.ChannelBufferOutputStream(messageBuffer);
stream.write(image);
msg_im_pub.setData(stream.buffer().copy());
stream.buffer().clear(); % Clear java buffer
publisher.publish(msg_im_pub);
Nice to meet you. I am Emily from Germany.
I am using the RosMatlab I/O package released on january 2014. I am having problems when trying to publish a PoseArray from Matlab to Rviz. I can send the message from Matlab. But Rviz can’t display the PoseArray, because it doesn’t set the “frame_id” of header file. Unfortunately, I can’t fins the way how to set them on the below code. Could you teach me how to set the frame_id or header file on RosMatlab?
with the next code :
node = rosmatlab.node('PublishArray', [], [], 'rosIP', '127.0.0.1');
publisher = rosmatlab.publisher('TOPIC', 'geometry_msgs/PoseArray', node);
msg = rosmatlab.message('geometry_msgs/PoseArray', node);
po = rosmatlab.message('geometry_msgs/Pose', node);
p = msg.getPoses();
po.getPosition().setX(0); po.getPosition().setY(0); po.getPosition().setZ(0);
po.getOrientation().setX(0); po.getOrientation().setY(0); po.getOrientation().setZ(0); po.getOrientation().setW(0);
p.add(po);
msg.setPoses(p);
publisher.publish(msg);
If I run the above code, the below message comes on the rviz and can’t display the posearray..
“[ WARN] [1421107372.814210366]: Invalid argument passed to canTransform argument source_frame in tf2 frame_ids cannot be empty”
I would appreciate it very much if you could advise me anything.
Best regards,
Emily
...
Dear Mr. Remo,
Thank you for giving me the detailed information!! I could publish the posearray : )
Could I ask another question? Now, I also have a problem to set “time_from_start” when publish a JointTrajectory from Matlab.
Could you teach me how to set the“time_from_start” on RosMatlab?
with the next code :
--------------------------------------------------------------------------------
node = rosmatlab.node('PublishTrajectory', [], [], 'rosIP', '127.0.0.1');
publisher = rosmatlab.publisher('Traj', 'trajectory_msgs/JointTrajectory', node);
msg = rosmatlab.message('trajectory_msgs/JointTrajectory', node);
po = rosmatlab.message('trajectory_msgs/JointTrajectoryPoint', node);
p1 = msg.getPoints();
po.setTimeFromStart(1);
p1.add(po);
msg.setPoints(p1);
publisher.publish(msg);
------------------------------------------------------------------------------------
If I run the above code, the below message comes on Matlab and can’t publish.
No method 'setTimeFromStart' with matching signature found for class 'org.ros.internal.message.$Proxy27'.
Error in JointTraj (line 27)
po.setTimeFromStart(1);
I would appreciate it very much if you could advise me anything.
Best regards,
Emily
...
【玖富娱乐】推荐主管QQ【708227】【玖富娱乐】推荐主管QQ【708227】
【玖富娱乐】推荐主管QQ【708227】【玖富娱乐】推荐主管QQ【708227】
Abraham Ayala於 2014年3月5日星期三 UTC+8上午1時31分50秒寫道: