MATLAB Robot Raconteur Client Example

 1function reynard_robotraconteur_client()
 2
 3% Connect to the Reynard service using a URL
 4c = RobotRaconteur.ConnectService('rr+tcp://localhost:29200?service=reynard');
 5
 6% Enable events. Don't use if no event listeners are connected
 7RobotRaconteur.EnableEvents(c);
 8
 9% Connect a callback function to listen for new messages
10evt = addlistener(c, 'new_message', @new_message_callback);
11
12% Read the current state using a wire "peek". Can also "connect" to receive streaming updates.
13state = c.state.PeekInValue();
14disp(state);
15
16% Teleport the robot
17c.teleport(0.1,-0.2);
18
19% Drive the robot with no timeout
20c.drive_robot(0.5,-0.2,-1,false);
21
22% Wait for one second
23pause(1)
24
25% Stop the robot
26c.drive_robot(0,0,-1,false);
27
28% Set the arm position
29c.setf_arm_position(deg2rad(100), deg2rad(-30), deg2rad(-70));
30
31% Drive the arm using timeout and wait
32c.drive_arm(deg2rad(10), deg2rad(-30), deg2rad(-15), 1.5, true);
33
34% Set the color to red
35c.color = [1,0,0]';
36
37% Read the color
38c_color = c.color;
39disp(c_color)
40
41pause(1);
42
43% Reset the color
44c.color = [0.929, 0.49, 0.192]';
45
46% Say hello
47c.say('Hello, World From Matlab!');
48
49% Process events using ProcessRequests() function.
50% Matlab is single threaded, so asynchronous events need to
51% be executed using ProcessRequests()
52for i=1:10
53    RobotRaconteur.ProcessRequests();
54    pause(0.1);
55end
56
57    % Callback function for new_message
58    function new_message_callback(msg)
59       disp(['New message: ' msg]);
60    end
61
62end