C# Robot Raconteur Client Example

 1using System;
 2using RobotRaconteur;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using System.Linq;
 6
 7// Initialize the client node
 8using (var node_setup = new ClientNodeSetup())
 9{
10    // Connect to the Reynard service using a URL
11    var c = (experimental.reynard_the_robot.Reynard)RobotRaconteurNode.s.ConnectService(
12        "rr+tcp://localhost:29200?service=reynard");
13
14    // Connect a callback function to listen for new messages
15    c.new_message += (msg) =>
16    { Console.WriteLine(msg); };
17
18    // Read the current state using a wire "peek". Can also "connect" to receive streaming updates.
19    var state = c.state.PeekInValue(out var state_ts);
20    Console.WriteLine(string.Join(",", state.robot_position.Select(x => x.ToString())));
21    Console.WriteLine(string.Join(",", state.arm_position.Select(x => x.ToString())));
22
23    // Teleport the robot
24    c.teleport(0.1, -0.2);
25
26    // Drive the robot with no timeout
27    c.drive_robot(0.5, -0.2, -1, false);
28
29    // Wait for one second
30    RobotRaconteurNode.s.Sleep(1000);
31
32    // Stop the robot
33    c.drive_robot(0, 0, -1, false);
34
35    // Set the arm position
36    c.setf_arm_position(100.0 * (Math.PI / 180), -30 * (Math.PI / 180), -70 * (Math.PI / 180));
37
38    // Drive the arm using timeout and wait
39    c.drive_arm(10.0 * (Math.PI / 180), -30 * (Math.PI / 180), -15 * (Math.PI / 180), 1.5, true);
40
41    //  Set the color to red
42    c.color = new double[] { 1.0, 0.0, 0.0 };
43
44    // Read the color
45    var color_in = c.color;
46    Console.WriteLine(string.Join(",", color_in.Select(x => x.ToString())));
47
48    RobotRaconteurNode.s.Sleep(1000);
49
50    // Reset the color
51    c.color = new double[] { 0.929, 0.49, 0.192 };
52
53    // Say hello
54    c.say("Hello, World From C#!");
55}