Skip to content
Snippets Groups Projects
Commit 1754194d authored by Damon Kohler's avatar Damon Kohler
Browse files

Adds new tutorial that solves a maze in Stage.

parent ad71463c
No related branches found
No related tags found
No related merge requests found
/*
* 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')
}
<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>
/*
* 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);
}
});
}
}
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")
rosjava_tutorial_right_hand_rule/world/maze.png

6.93 KiB

...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
include 'rosjava_bootstrap', 'rosjava_messages', 'apache_xmlrpc_common', include 'rosjava_bootstrap', 'rosjava_messages', 'apache_xmlrpc_common',
'apache_xmlrpc_client', 'apache_xmlrpc_server', 'rosjava', 'apache_xmlrpc_client', 'apache_xmlrpc_server', 'rosjava',
'rosjava_geometry', 'rosjava_tutorial_pubsub', 'rosjava_geometry', 'rosjava_tutorial_pubsub',
'rosjava_tutorial_services', 'rosjava_benchmarks', 'rosjava_tutorial_services', 'rosjava_tutorial_right_hand_rule',
'rosjava_test', 'docs' 'rosjava_benchmarks', 'rosjava_test', 'docs'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment