An oldie but a goodie. Was thinking to just implement the locomotion using good old genetic programming.
You could probably generate a walking robot using a genetic algorithm that repeated the tree’s actions a number of times. Bet it would be faster than the whole neural network policy training replay buffer spiel.
While looking at the stable baselines docs, I came across PER:
https://arxiv.org/pdf/1511.05952.pdf
I saw it in the parameters of DQN (https://openai.com/blog/openai-baselines-dqn/ )- It was OpenAI's 2017 algorithm. released when they released their baselines).
model = DQN(‘MlpPolicy’, env, learning_rate=1e-3, prioritized_replay=True, verbose=1)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/gym/envs/registration.py", line 106, in spec
importlib.import_module(mod_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'gym-robotable'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ppo2.py", line 29, in <module>
env = gym.make(hp.env_name)
File "/usr/local/lib/python3.6/dist-packages/gym/envs/registration.py", line 142, in make
return registry.make(id, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/gym/envs/registration.py", line 86, in make
spec = self.spec(path)
File "/usr/local/lib/python3.6/dist-packages/gym/envs/registration.py", line 109, in spec
raise error.Error('A module ({}) was specified for the environment but was not found, make sure the package is installed with `pip install` before calling `gym.make()`'.format(mod_name))
gym.error.Error: A module (gym-robotable) was specified for the environment but was not found, make sure the package is installed with `pip install` before calling `gym.make()`
Registration… hmm ARS.py doesn’t complain. We had this problem before.
if __name__ == "__main__":
hp = Hp()
env = gym.make(hp.env_name)
model = PPO2(MlpPolicy, env, verbose=1)
model.learn(total_timesteps=10000)
for episode in range(100):
obs = env.reset()
for i in range(1000):
action, _states = model.predict(obs)
obs, rewards, dones, info = env.step(action)
#env.render()
if dones:
print("Episode finished after {} timesteps".format(i + 1))
break
env.render(mode="human")
def ConvertFromLegModel(self, actions):
"""Convert the actions that use leg model to the real motor actions.
Args:
actions: The theta, phi of the leg model.
Returns:
The eight desired motor angles that can be used in ApplyActions().
"""
COPY THE ACTIONS.
motor_angle = copy.deepcopy(actions)
DEFINE SOME THINGS
scale_for_singularity = 1
offset_for_singularity = 1.5
half_num_motors = int(self.num_motors / 2)
quarter_pi = math.pi / 4
FOR EVERY MOTOR
for i in range(self.num_motors):
THE ACTION INDEX IS THE FLOOR OF HALF. 00112233
action_idx = int(i // 2)
WELL, SO, THE FORWARD BACKWARD COMPONENT is
negative thingy times 45 degrees times (the action of the index plus half the motors.... plus the offset thingy)
forward_backward_component = (
-scale_for_singularity * quarter_pi *
(actions[action_idx + half_num_motors] + offset_for_singularity))
AND SO THE EXTENSION COMPONENT IS either + or - 45 degrees times the action.
extension_component = (-1)**i * quarter_pi * actions[action_idx]
IF 4,5,6,7 MAKE THAT THING NEGATIVE.
if i >= half_num_motors:
extension_component = -extension_component
THE ANGLE IS... PI + thingy 1 + thingy 2.
motor_angle[i] = (math.pi + forward_backward_component + extension_component)
return motor_angle
Ok my error is,
File "/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py", line 350, in step
action = self._transform_action_to_motor_command(action)
File "/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py", line 313, in _transform_action_to_motor_command
action = self.robotable.ConvertFromLegModel(action)
AttributeError: 'Robotable' object has no attribute 'ConvertFromLegModel'
Ok anyway i debugged for an hour and now it’s doing something. it’s saving numpy files now.
AttributeError: ‘Robotable’ object has no attribute ‘Reset’
Ok so I’ve got robot.urdf looking like a table, and loading. But there’s various differences between the minitaur gym env and my own minitaur, the robotable. Gotta compare, etc. ok it wants reset() not Reset(…)
just a warning:
No inertial data for link, using mass=1, localinertiadiagonal = 1,1,1, identity local inertial frameb3Warning[examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp,126]: torsob3Warning[examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp,126]:
happy with 1 defaults for mass and inertia settings, for now.
Ok so apparently just working my way through the bugs one by one. That’s probably as good a method as any :
File “/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py”, line 493, in _get_observation observation.extend(self.robotable.GetMotorAngles().tolist()) AttributeError: ‘Robotable’ object has no attribute ‘GetMotorAngles’
K did a :%s/Get/get/g in vi. NEXT.
File “/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py”, line 301, in reset return self._get_observation() File “/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py”, line 493, in _get_observation observation.extend(self.robotable.getMotorAngles().tolist()) File “/opt/gym-robotable/gym_robotable/envs/robotable.py”, line 88, in getMotorAngles jointState = p.getJointState(self.quadruped, self.motorIdList[i]) IndexError: list index out of range
ok self.nMotors = 4
File "/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py", line 527, in _get_observation_upper_bound
num_motors = self.robotable.num_motors
AttributeError: 'Robotable' object has no attribute 'num_motors'
k lets change nMotors to num_motors. NEXT
File “ars.py”, line 77, in ExploreWorker state, reward, done, _ = env.step(action) File “/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py”, line 350, in step action = self._transform_action_to_motor_command(action) File “/opt/gym-robotable/gym_robotable/envs/robotable_gym_env.py”, line 313, in _transform_action_to_motor_command action = self.robotable.ConvertFromLegModel(action) AttributeError: ‘Robotable’ object has no attribute ‘ConvertFromLegModel’
What is a ros topic? http://wiki.ros.org/Topics ROS can publish the webcam stream to a “topic”, and any part of the robot can subscribe to it, by name, if it is interested in that data. ROS is almost like a program where everything is a global variable.