Closed aysegulucar2016 closed 6 years ago
Dear David,
Many thanks for your support.
Sincerely
On Tue, Mar 13, 2018 at 10:44 AM, David Mansolino notifications@github.com wrote:
Yes, Webots now supports Python 2.7 controllers for the Darwin-op and Robotis-op2.
Here is a simple example controller:
"""This controller uses built-in motion manager modules to get the OP2 to walk..""" import osimport sysfrom controller import Robotfrom controller import LED
Path operations to correctly locate the managers.if sys.version_info.major > 2:
sys.exit("RobotisOpManager library is available ony for Python 2.7")
libraryPath = os.path.join(os.environ.get("WEBOTS_HOME"), 'projects', 'robots', 'robotis', 'darwin-op', 'libraries', 'python') libraryPath = libraryPath.replace('/', os.sep) sys.path.append(libraryPath) from managers import RobotisOp2GaitManager, RobotisOp2MotionManager
Names of position sensors needed to get the corresponding device and read the measurements.
positionSensorNames = ('ShoulderR', 'ShoulderL', 'ArmUpperR', 'ArmUpperL', 'ArmLowerR', 'ArmLowerL', 'PelvYR', 'PelvYL', 'PelvR', 'PelvL', 'LegUpperR', 'LegUpperL', 'LegLowerR', 'LegLowerL', 'AnkleR', 'AnkleL', 'FootR', 'FootL', 'Neck', 'Head')# List of position sensor devices. positionSensors = []
Create the Robot instance.
robot = Robot() basicTimeStep = int(robot.getBasicTimeStep())# Initialize motion manager. motionManager = RobotisOp2MotionManager(robot)# Get the time step of the current world. timestep = int(robot.getBasicTimeStep())
Retrieve devices.
headLed = robot.getLED('HeadLed') eyeLed = robot.getLED('EyeLed') gyro = robot.getGyro('Gyro')
Enable all the position sensors and populate the 'positionSensor' list.for i in range(0, len(positionSensorNames)):
positionSensors.append(robot.getPositionSensor(positionSensorNames[i] + 'S')) positionSensors[i].enable(basicTimeStep)
Initialize the LED devices.
headLed.set(0xff0000) eyeLed.set(0xa0a0ff)# Enable gyro device. gyro.enable(basicTimeStep)
Perform one simulation step to get sensors working properly.
robot.step(timestep)
Page 1: stand up.# Page 9: assume walking position.
motionManager.playPage(1, True) motionManager.playPage(9, True)
Initialize OP2 gait manager.
gaitManager = None gaitManager = RobotisOp2GaitManager(robot, "") gaitManager.start() gaitManager.setXAmplitude(0.0) gaitManager.setYAmplitude(0.0) gaitManager.setBalanceEnable(True) gaitAmplitude = 0.5 looptimes = 0
Main loop: perform a simulation step until the simulation is over.# At the beginning, start walking on the spot.# After 45 timesteps, begin taking steps forward.while robot.step(timestep) != -1:
if looptimes == 45: gaitManager.setXAmplitude(gaitAmplitude) gaitManager.step(basicTimeStep) looptimes += 1
Note that this controller will work out of the box in the simulation and in remote-controle mode with the real robot too. However, the cross-compilation is not working out of the box for python controllers (if you need cross-compilation for python controller let us know).
Sincerely, David
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/darwinop/webots-cross-compilation/issues/272#issuecomment-372574855, or mute the thread https://github.com/notifications/unsubscribe-auth/AP-0rlybUghi-8WdEyGDK5gGJW1Toc1Kks5td3jKgaJpZM4SoGMe .
Yes, Webots now supports Python 2.7 controllers for the Darwin-op and Robotis-op2.
Here is a simple example controller:
Note that this controller will work out of the box in the simulation and in remote-controle mode with the real robot too. However, the cross-compilation is not working out of the box for python controllers (if you need cross-compilation for python controller let us know).
Sincerely, David