Commit 40c41a27 authored by Séverin Lemaignan's avatar Séverin Lemaignan
Browse files

Initial commit

parents
__pycache__
*.blend1
#! /usr/bin/env morseexec
""" Basic MORSE simulation scene for <robopilot-sim> environment
Feel free to edit this template as you like!
"""
from morse.builder import *
from robopilotsim.builder.robots import Van, Vehicle
from robopilotsim.builder.actuators import Pathfollower
# add a new van robot in the simulation
van = Van()
# The list of the main methods to manipulate your components
# is here: http://www.openrobots.org/morse/doc/stable/user/builder_overview.html
van.translate(-28.0, -48.0, 0.0)
van.rotate(0.0, 0.0, 3.5)
# Add a motion controller
# Check here the other available actuators:
# http://www.openrobots.org/morse/doc/stable/components_library.html#actuators
#
# 'morse add actuator <name> robopilot-sim' can help you with the creation of a custom
# actuator.
motion = MotionVW()
van.append(motion)
bike=Vehicle(type="bike")
bike.translate(-55.308, -53.882, 0.03)
car=Vehicle(type="car")
car.translate(-58.85, -48.627, 0.03)
# create a new pathfollower actuator
#pathfollower = Pathfollower()
#pathfollower.properties(Path="path1")
#van.append(pathfollower)
# Add a keyboard controller to move the robot with arrow keys.
keyboard = Keyboard()
van.append(keyboard)
keyboard.properties(ControlType = 'Position')
pose = Pose()
van.append(pose)
van.add_default_interface('socket')
env = Environment('data/robopilotsim/env/bristol.blend', fastmode = False)
env.set_camera_location([-12.7, -27.6, 205.2])
env.set_camera_rotation([0, 0, 0])
#env.set_camera_location([32.7, -38.4, 27.7])
#env.set_camera_rotation([1.24, 0, 1.73])
env.set_camera_clip(0.5,600)
env.set_camera_focal_length(20) #mm
env.set_camera_speed(10)
env.set_material_mode("MULTITEXTURE")
env.set_viewport("SOLID")
env.fullscreen()
import logging; logger = logging.getLogger("morse." + __name__)
import morse.core.actuator
from morse.core.services import service, async_service, interruptible
from morse.core import status, blenderapi
from morse.helpers.components import add_data, add_property
class Pathfollower(morse.core.actuator.Actuator):
"""Write here the general documentation of your actuator.
It will appear in the generated online documentation.
"""
_name = "Pathfollower"
_short_desc = "Follows a pre-created path"
# define here the data fields required by your actuator
# format is: field name, initial value, type, description
add_property('_pathname', "path", "Path", 'str', 'Name of the Blender path object')
add_property('_loop', True, "Loop", 'bool', 'if true, the robot jumps back at the begining of the path after reaching the end, and keep doing so.')
def __init__(self, obj, parent=None):
logger.info("%s initialization" % obj.name)
# Call the constructor of the parent class
morse.core.actuator.Actuator.__init__(self, obj, parent)
import pdb;pdb.set_trace()
self._path=blenderapi.scene().objects[self._pathname]
logger.info('Component initialized -- using path <%s>' % self._pathname)
@service
def get_counter(self):
""" This is a sample service.
Simply returns the value of the internal counter.
You can access it as a RPC service from clients.
"""
logger.info("%s counter is %s" % (self.name, self.local_data['counter']))
return self.local_data['counter']
@interruptible
@async_service
def async_test(self, value):
""" This is a sample asynchronous service.
Returns when the internal counter reaches ``value``.
You can access it as a RPC service from clients.
"""
self._target_count = value
def default_action(self):
""" Main loop of the actuator.
Implements the component behaviour
"""
# check if we have an on-going asynchronous tasks...
if self._target_count and self.local_data['counter'] > self._target_count:
self.completed(status.SUCCESS, self.local_data['counter'])
# implement here the behaviour of your actuator
self.local_data['counter'] += 1
from morse.builder.creator import ActuatorCreator
class Pathfollower(ActuatorCreator):
_classpath = "robopilotsim.actuators.pathfollower.Pathfollower"
_blendname = "pathfollower"
def __init__(self, name=None):
ActuatorCreator.__init__(self, name)
from .van import Van
from .vehicle import Vehicle
from morse.builder import *
class Van(GroundRobot):
"""
A template robot model for van, with a motion controller and a pose sensor.
"""
def __init__(self, name = None, debug = True):
# van.blend is located in the data/robots directory
GroundRobot.__init__(self, 'robopilotsim/robots/van.blend', name)
self.properties(classpath = "robopilotsim.robots.van.Van")
###################################
# Actuators
###################################
# (v,w) motion controller
# Check here the other available actuators:
# http://www.openrobots.org/morse/doc/stable/components_library.html#actuators
self.motion = MotionVW()
self.append(self.motion)
# Optionally allow to move the robot with the keyboard
if debug:
keyboard = Keyboard()
keyboard.properties(ControlType = 'Position')
self.append(keyboard)
###################################
# Sensors
###################################
self.pose = Pose()
self.append(self.pose)
from morse.builder import *
class Vehicle(GroundRobot):
"""
Vehicles (cars, bikes) to animate the simulated environment
"""
def __init__(self,type="car", color=(0.2, 0.5, 0.6), name = None, debug = True):
# vehicle.blend is located in the data/robots directory
GroundRobot.__init__(self, filename='data/robopilotsim/props/%s.blend' % type,
name=name)
self.properties(classpath = "robopilotsim.robots.vehicle.Vehicle")
###################################
# Actuators
###################################
# (v,w) motion controller
# Check here the other available actuators:
# http://www.openrobots.org/morse/doc/stable/components_library.html#actuators
self.motion = Waypoint()
self.append(self.motion)
# Optionally allow to move the robot with the keyboard
if debug:
keyboard = Keyboard()
keyboard.properties(ControlType = 'Position')
self.append(keyboard)
###################################
# Sensors
###################################
#self.pose = Pose()
#self.append(self.pose)
mesh_obj = None
for c in self._bpy_object.children:
if c.name.endswith("_mesh"):
mesh_obj = c
break
if mesh_obj:
mats = mesh_obj.material_slots.keys()
[body_mat] = [mat for mat in mats if mat.startswith('body')] # account for body.001, body.002...
mesh_obj.material_slots[body_mat].material.diffuse_color = color
import logging; logger = logging.getLogger("morse." + __name__)
import morse.core.robot
class Van(morse.core.robot.Robot):
"""
Class definition for the van robot.
"""
_name = 'van robot'
def __init__(self, obj, parent=None):
""" Constructor method
Receives the reference to the Blender object.
Optionally it gets the name of the object's parent,
but that information is not currently used for a robot.
"""
logger.info('%s initialization' % obj.name)
morse.core.robot.Robot.__init__(self, obj, parent)
# Do here robot specific initializations
logger.info('Component initialized')
def default_action(self):
""" Main loop of the robot
"""
# This is usually not used (responsibility of the actuators
# and sensors). But you can add here robot-level actions.
pass
import logging; logger = logging.getLogger("morse." + __name__)
import morse.core.robot
class Vehicle(morse.core.robot.Robot):
"""
Class definition for the vehicle robot.
"""
_name = 'vehicle robot'
def __init__(self, obj, parent=None):
""" Constructor method
Receives the reference to the Blender object.
Optionally it gets the name of the object's parent,
but that information is not currently used for a robot.
"""
logger.info('%s initialization' % obj.name)
morse.core.robot.Robot.__init__(self, obj, parent)
# Do here robot specific initializations
logger.info('Vehicle initialized')
def default_action(self):
""" Main loop of the robot
"""
# This is usually not used (responsibility of the actuators
# and sensors). But you can add here robot-level actions.
pass
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment