Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Elephant Robotics
Published © GPL3+

Beginner-friendly Case of Imitation Learning with myCobot

This article leverages pybullet and the myCobot 320 model to provide a quick and accessible imitation learning case.

BeginnerFull instructions provided1 hour203

Things used in this project

Hardware components

ESP32 Basic Core IoT Development Kit
M5Stack ESP32 Basic Core IoT Development Kit
×1

Hand tools and fabrication machines

myCobot 320 m5
Elephant Robotics myCobot 320 m5

Story

Read more

Schematics

mycobot_320_urdf

Code

data_collection.py

Python
import pybullet as p
import pybullet_data as pd
import numpy as np
import time

# use PyBullet
client_id = p.connect(p.GUI)
p.setAdditionalSearchPath(pd.getDataPath())
p.setGravity(0, 0, -9.8)

# load 2 model  a plane and a robot
plane_id = p.loadURDF("plane.urdf")
robot_id = p.loadURDF("mycobot_description/urdf/mycobot/mycobot_urdf.urdf", useFixedBase=True)

# set step
time_step = 1/240
p.setTimeStep(time_step)

states = []
actions = []

for i in range(100):
    joint_positions = [0, 0.3*np.sin(i/10), -np.pi/4, 0, np.pi/4, 0]
    states.append(joint_positions)
    actions.append(joint_positions)  # In imitation learning, the ideal action is the correct state
    
    p.setJointMotorControlArray(robot_id, range(6), p.POSITION_CONTROL, targetPositions=joint_positions)
    p.stepSimulation()
    time.sleep(time_step)

# save data
np.save("states.npy", np.array(states))
p.save("actions.npy", np.array(actions))

simple-imitation-learning

Credits

Elephant Robotics
103 projects • 218 followers
An Innovative Robotics Company.
Contact

Comments

Please log in or sign up to comment.