Java Robot Raconteur Client Example

 1import java.io.Console;
 2import java.util.*;
 3import com.robotraconteur.*;
 4
 5public class reynard_robotraconteur_client
 6{
 7    public static void main(String[] args)
 8    {
 9
10        // Initialize the client node
11        ClientNodeSetup node_setup = new ClientNodeSetup();
12        try
13        {
14            // Register service type
15            RobotRaconteurNode.s().registerServiceType(
16                new experimental.reynard_the_robot.experimental__reynard_the_robotFactory());
17
18            // Connect to the Reynard service using a URL
19            experimental.reynard_the_robot.Reynard c =
20                (experimental.reynard_the_robot.Reynard)RobotRaconteurNode.s().connectService(
21                    "rr+tcp://localhost:29200?service=reynard");
22
23            // Connect a callback function to listen for new messages
24            // c.new_message += (msg) => { Console.WriteLine(msg); };
25
26            // Read the current state using a wire "peek". Can also "connect" to receive streaming updates.
27            experimental.reynard_the_robot.ReynardState state = c.get_state().peekInValue();
28
29            // Teleport the robot
30            c.teleport(0.1, -0.2);
31
32            // Drive the robot with no timeout
33            c.drive_robot(0.5, -0.2, -1, false);
34
35            // Wait for one second
36            RobotRaconteurNode.s().sleep(1000);
37
38            // Stop the robot
39            c.drive_robot(0, 0, -1, false);
40
41            // Set the arm position
42            c.setf_arm_position(100.0 * (Math.PI / 180), -30 * (Math.PI / 180), -70 * (Math.PI / 180));
43
44            // Drive the arm using timeout and wait
45            c.drive_arm(10.0 * (Math.PI / 180), -30 * (Math.PI / 180), -15 * (Math.PI / 180), 1.5, true);
46
47            //  Set the color to red
48            c.set_color(new double[] {1.0, 0.0, 0.0});
49
50            // Read the color
51            double[] color_in = c.get_color();
52
53            RobotRaconteurNode.s().sleep(1000);
54
55            // Reset the color
56            c.set_color(new double[] {0.929, 0.49, 0.192});
57
58            // Say hello
59            c.say("Hello, World From Java!");
60        }
61        finally
62        {
63            // Shutdown the client node
64            node_setup.finalize();
65        }
66    }
67}