Run the following commands in the terminal then refresh this page. Check the JavaScript
16 | console for the output.
17 |
25 |
26 | Connecting to rosbridge...
27 |
28 |
29 | Connected
30 |
31 |
32 | Error in the backend!
33 |
34 |
35 | Connection closed.
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/html-front-end/robot_function.js:
--------------------------------------------------------------------------------
1 | // Connecting to ROS
2 | // -----------------
3 | var ros = new ROSLIB.Ros();
4 | // If there is an error on the backend, an 'error' emit will be emitted.
5 | ros.on('error', function(error) {
6 | console.log(error);
7 | });
8 | // Find out exactly when we made a connection.
9 | ros.on('connection', function() {
10 | console.log('Connection made!');
11 | });
12 | ros.on('close', function() {
13 | console.log('Connection closed.');
14 | });
15 | // Create a connection to the rosbridge WebSocket server.
16 | ros.connect("ws://" + window.location.hostname + ":9090");
17 | // Publishing a Topic
18 | // ------------------
19 | // First, we create a Topic object with details of the topic's name and message type.
20 | var cmdVel = new ROSLIB.Topic({
21 | ros : ros,
22 | name : '/robot0/twist',
23 | messageType : 'geometry_msgs/Twist'
24 | });
25 | // Then we create the payload to be published. The object we pass in to ros.Message matches the
26 | // fields defined in the geometry_msgs/Twist.msg definition.
27 | var twist = new ROSLIB.Message({
28 | linear : {
29 | x : 0,
30 | y : 0,
31 | z : 0
32 | },
33 | angular : {
34 | x : 0,
35 | y : 0,
36 | z : 0
37 | }
38 | });
39 | // And finally, publish.
40 | cmdVel.publish(twist);
41 | //Subscribing to a Topic
42 | //----------------------
43 | // Like when publishing a topic, we first create a Topic object with details of the topic's name
44 | // and message type. Note that we can call publish or subscribe on the same topic object.
45 | var listener = new ROSLIB.Topic({
46 | ros : ros,
47 | name : '/listener',
48 | messageType : 'std_msgs/String'
49 | });
50 | // Then we add a callback to be called every time a message is published on this topic.
51 |
52 | // Calling a service
53 | // -----------------
54 | // First, we create a Service client with details of the service's name and service type.
55 |
56 | // Then we create a Service Request. The object we pass in to ROSLIB.ServiceRequest matches the
57 | // fields defined in the rospy_tutorials AddTwoInts.srv file.
58 | var request = new ROSLIB.ServiceRequest({
59 | a : 1,
60 | b : 2
61 | });
62 | // Setting a param value
63 | // ---------------------
64 | ros.getParams(function(params) {
65 | console.log(params);
66 | });
67 | // First, we create a Param object with the name of the param.
68 | var maxVelX = new ROSLIB.Param({
69 | ros : ros,
70 | name : 'max_vel_y'
71 | });
72 | //Then we set the value of the param, which is sent to the ROS Parameter Server.
73 | maxVelX.set(0.8);
74 | maxVelX.get(function(value) {
75 | console.log('MAX VAL: ' + value);
76 | });
77 | // Getting a param value
78 | // ---------------------
79 | var favoriteColor = new ROSLIB.Param({
80 | ros : ros,
81 | name : 'favorite_color'
82 | });
83 |
84 | favoriteColor.set('red');
85 | favoriteColor.get(function(value) {
86 | console.log('My robot\'s favorite color is ' + value);
87 |
88 | })
89 |
90 | function moveX(inputX){
91 | var twist2 = new ROSLIB.Message({
92 | linear : {
93 | x : inputX,
94 | y : 0,
95 | z : 0
96 | },
97 | angular : {
98 | x : 0,
99 | y : 0,
100 | z : 0
101 | }
102 | });
103 | // And finally, publish.
104 | cmdVel.publish(twist2);
105 | }
106 |
107 | function rotateZ(inputZ){
108 | var twist = new ROSLIB.Message({
109 | linear : {
110 | x : 0,
111 | y : 0,
112 | z : 0
113 | },
114 | angular : {
115 | x : 0,
116 | y : 0,
117 | z : inputZ
118 | }
119 | });
120 | // And finally, publish.
121 | cmdVel.publish(twist);
122 | }
123 | ;
--------------------------------------------------------------------------------
/joy/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | ^^^^^^^^^^^^^^^^^^^^^^^^^
2 | Changelog for package joy
3 | ^^^^^^^^^^^^^^^^^^^^^^^^^
4 |
5 | 1.10.1 (2015-05-24)
6 | -------------------
7 | * Remove stray architechture_independent flags
8 | * Contributors: Jonathan Bohren, Scott K Logan
9 |
10 | 1.10.0 (2014-06-26)
11 | -------------------
12 | * First indigo release
13 |
--------------------------------------------------------------------------------
/joy/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # http://ros.org/doc/groovy/api/catkin/html/user_guide/supposed.html
2 | cmake_minimum_required(VERSION 2.8.3)
3 | project(joy)
4 |
5 | # Load catkin and all dependencies required for this package
6 | set(CATKIN_DEPS roscpp diagnostic_updater sensor_msgs)
7 | set(ROSDEP_DEPS joystick)
8 | find_package(catkin REQUIRED ${CATKIN_DEPS})
9 | catkin_package(DEPENDS ${CATKIN_DEPS} ${ROSDEP_DEPS})
10 |
11 | # Look for