diff --git a/rosjava_tutorial_right_hand_rule/build.gradle b/rosjava_tutorial_right_hand_rule/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..16f16ee35ab94ff3177f72faa6e32e3597c90eac --- /dev/null +++ b/rosjava_tutorial_right_hand_rule/build.gradle @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2011 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +apply plugin: 'application' + +mainClassName = 'org.ros.RosRun' + +dependencies { + compile project(':rosjava') +} + diff --git a/rosjava_tutorial_right_hand_rule/manifest.xml b/rosjava_tutorial_right_hand_rule/manifest.xml new file mode 100644 index 0000000000000000000000000000000000000000..a8cd8f1a8ebfc78509528b87b3fcfa3f5085911b --- /dev/null +++ b/rosjava_tutorial_right_hand_rule/manifest.xml @@ -0,0 +1,10 @@ +<package> + <description brief="rosjava_tutorial_right_hand_rule"> + rosjava_tutorial_right_hand_rule is a simple example project that solves a maze in Stage. + </description> + <author>Damon Kohler</author> + <license>Apache 2.0</license> + <review status="unreviewed" notes="" /> + <url>http://ros.org/wiki/rosjava_tutorial_right_hand_rule</url> +</package> + diff --git a/rosjava_tutorial_right_hand_rule/src/main/java/org/ros/rosjava_tutorial_right_hand_rule/RightHandRule.java b/rosjava_tutorial_right_hand_rule/src/main/java/org/ros/rosjava_tutorial_right_hand_rule/RightHandRule.java new file mode 100644 index 0000000000000000000000000000000000000000..1bafae60749170de1350055271099f5a5bcda4a7 --- /dev/null +++ b/rosjava_tutorial_right_hand_rule/src/main/java/org/ros/rosjava_tutorial_right_hand_rule/RightHandRule.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.ros.rosjava_tutorial_right_hand_rule; + +import org.ros.message.MessageListener; +import org.ros.namespace.GraphName; +import org.ros.node.AbstractNodeMain; +import org.ros.node.ConnectedNode; +import org.ros.node.topic.Publisher; +import org.ros.node.topic.Subscriber; + +/** + * @author damonkohler@google.com (Damon Kohler) + */ +public class RightHandRule extends AbstractNodeMain { + + @Override + public GraphName getDefaultNodeName() { + return GraphName.of("right_hand_rule"); + } + + @Override + public void onStart(ConnectedNode connectedNode) { + final Publisher<geometry_msgs.Twist> publisher = + connectedNode.newPublisher("cmd_vel", geometry_msgs.Twist._TYPE); + final geometry_msgs.Twist twist = publisher.newMessage(); + final Subscriber<sensor_msgs.LaserScan> subscriber = + connectedNode.newSubscriber("base_scan", sensor_msgs.LaserScan._TYPE); + subscriber.addMessageListener(new MessageListener<sensor_msgs.LaserScan>() { + @Override + public void onNewMessage(sensor_msgs.LaserScan message) { + float[] ranges = message.getRanges(); + float northRange = ranges[ranges.length / 2]; + float northEastRange = ranges[ranges.length / 3]; + double linearVelocity = 0.5; + double angularVelocity = -0.5; + if (northRange < 1. || northEastRange < 1.) { + linearVelocity = 0; + angularVelocity = 0.5; + } + twist.getAngular().setZ(angularVelocity); + twist.getLinear().setX(linearVelocity); + publisher.publish(twist); + } + }); + } +} diff --git a/rosjava_tutorial_right_hand_rule/world/maze-erratic.world b/rosjava_tutorial_right_hand_rule/world/maze-erratic.world new file mode 100644 index 0000000000000000000000000000000000000000..f5b647785d02a1d7a4ba9627dbb3e1d494262c3f --- /dev/null +++ b/rosjava_tutorial_right_hand_rule/world/maze-erratic.world @@ -0,0 +1,63 @@ +define topurg ranger +( + sensor( + range [ 0.0 30.0 ] + fov 270.25 + samples 1081 + ) + + # generic model properties + color "black" + size [ 0.05 0.05 0.1 ] +) + +define erratic position +( + size [0.35 0.35 0.25] + origin [-0.05 0 0 0] + gui_nose 1 + drive "diff" + topurg(pose [ 0.050 0.000 0 0.000 ]) +) + +define floorplan model +( + # sombre, sensible, artistic + color "gray30" + + # most maps will need a bounding box + boundary 0 + + gui_nose 0 + gui_grid 0 + + gui_outline 0 + gripper_return 0 + fiducial_return 0 + laser_return 1 +) + +# set the resolution of the underlying raytrace model in meters +resolution 0.02 + +interval_sim 100 # simulation timestep in milliseconds + +window +( + size [ 500.0 500.0 ] + rotate [ 0.0 0.0 ] + scale 10.0 +) + +# load an environment bitmap +floorplan +( + name "maze" + bitmap "maze.png" + size [50.0 50.0 0.5] + pose [ 0.0 0.0 0 0.0 ] + gui_move 0 +) + +# throw in a robot +erratic( pose [ 1.25 -25.0 0.0 90.0 ] name "era" color "blue") diff --git a/rosjava_tutorial_right_hand_rule/world/maze.png b/rosjava_tutorial_right_hand_rule/world/maze.png new file mode 100644 index 0000000000000000000000000000000000000000..ed9ab46dce6f7df6ac425089a154b150c5d2dd90 Binary files /dev/null and b/rosjava_tutorial_right_hand_rule/world/maze.png differ diff --git a/settings.gradle b/settings.gradle index 3bb6080f1f7c8a6566e76d76537caf93e2ef327c..f6287ece6b180af6944d37b269629279352fca28 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,5 +17,5 @@ include 'rosjava_bootstrap', 'rosjava_messages', 'apache_xmlrpc_common', 'apache_xmlrpc_client', 'apache_xmlrpc_server', 'rosjava', 'rosjava_geometry', 'rosjava_tutorial_pubsub', - 'rosjava_tutorial_services', 'rosjava_benchmarks', - 'rosjava_test', 'docs' + 'rosjava_tutorial_services', 'rosjava_tutorial_right_hand_rule', + 'rosjava_benchmarks', 'rosjava_test', 'docs'