-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from cyberbotics/sync
Sync with 'webots' repo.
- Loading branch information
Showing
37 changed files
with
3,146 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<!-- start Webots --> | ||
<arg name="no-gui" default="false," doc="Start Webots with minimal GUI"/> | ||
<include file="$(find webots_ros)/launch/webots.launch"> | ||
<arg name="mode" value="realtime"/> | ||
<arg name="no-gui" value="$(arg no-gui)"/> | ||
<arg name="world" value="$(find webots_ros)/worlds/ros_python.wbt"/> | ||
</include> | ||
|
||
<arg name="auto-close" default="false" doc="Startup mode"/> | ||
<env name="LD_LIBRARY_PATH" value="$(env LD_LIBRARY_PATH):$(env WEBOTS_HOME)/lib/controller"/> | ||
<env name="PYTHONPATH" value="$(env PYTHONPATH):$(env WEBOTS_HOME)/lib/controller/python27" unless="$(eval '1' if env('ROS_DISTRO') == 'noetic' else '0')" /> | ||
<env name="PYTHONPATH" value="$(env PYTHONPATH):$(env WEBOTS_HOME)/lib/controller/python38" if="$(eval '1' if env('ROS_DISTRO') == 'noetic' else '0')" /> | ||
<node name="webots_ros_python" pkg="webots_ros" type="ros_python.py" required="$(arg auto-close)"/> | ||
<node name="ros_controller" pkg="webots_ros" type="ros_controller.py" required="$(arg auto-close)"/> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div> | ||
<h2>Info window</h2> | ||
<div> | ||
<p>Show message received from the controller:</p> | ||
<span id='text-display'></span> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
webots.window('info').receive = function(message, robot) { | ||
if (message.startsWith('test')) { | ||
document.querySelector("#text-display").innerHTML = message; | ||
this.send("Answer: " + message, robot); | ||
} else | ||
console.log("Received unknown message for robot '" + robot + "': '" + message + "'"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 1996-2020 Cyberbotics Ltd. | ||
# | ||
# 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. | ||
|
||
""" | ||
This is a simple example of a Python ROS node receiving sensor values and publishing motor commands (velocity) | ||
to drive a robot and stop it before colliding with an obstacle. | ||
""" | ||
|
||
import rospy | ||
from std_msgs.msg import Float64 | ||
|
||
|
||
def callback(data): | ||
global pub | ||
rospy.loginfo(rospy.get_caller_id() + 'Received sensor value: %s', data.data) | ||
if data.data > 100: | ||
pub.publish(0) | ||
else: | ||
pub.publish(9) | ||
|
||
|
||
rospy.init_node('controller', anonymous=True) | ||
pub = rospy.Publisher('motor', Float64, queue_size=10) | ||
rospy.Subscriber("sensor", Float64, callback) | ||
rospy.spin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 1996-2020 Cyberbotics Ltd. | ||
# | ||
# 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. | ||
|
||
""" | ||
This is a simple example of a Webots controller running a Python ROS node thanks to rospy. | ||
The robot is publishing the value of its front distance sensor and receving motor commands (velocity). | ||
""" | ||
|
||
import rospy | ||
from std_msgs.msg import Float64 | ||
from controller import Robot | ||
import os | ||
|
||
|
||
def callback(data): | ||
global velocity | ||
global message | ||
message = 'Received velocity value: ' + str(data.data) | ||
velocity = data.data | ||
|
||
|
||
robot = Robot() | ||
timeStep = int(robot.getBasicTimeStep()) | ||
left = robot.getMotor('motor.left') | ||
right = robot.getMotor('motor.right') | ||
sensor = robot.getDistanceSensor('prox.horizontal.2') # front central proximity sensor | ||
sensor.enable(timeStep) | ||
left.setPosition(float('inf')) # turn on velocity control for both motors | ||
right.setPosition(float('inf')) | ||
velocity = 0 | ||
left.setVelocity(velocity) | ||
right.setVelocity(velocity) | ||
message = '' | ||
print('Initializing ROS: connecting to ' + os.environ['ROS_MASTER_URI']) | ||
robot.step(timeStep) | ||
rospy.init_node('listener', anonymous=True) | ||
print('Subscribing to "motor" topic') | ||
robot.step(timeStep) | ||
rospy.Subscriber('motor', Float64, callback) | ||
pub = rospy.Publisher('sensor', Float64, queue_size=10) | ||
print('Running the control loop') | ||
while robot.step(timeStep) != -1 and not rospy.is_shutdown(): | ||
pub.publish(sensor.getValue()) | ||
print('Published sensor value: ', sensor.getValue()) | ||
if message: | ||
print(message) | ||
message = '' | ||
left.setVelocity(velocity) | ||
right.setVelocity(velocity) |
File renamed without changes.
Oops, something went wrong.