How to control the joint rotation

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
krishna
Posts: 1
Joined: Fri Jan 17, 2020 6:30 am

How to control the joint rotation

Post by krishna »

Hello,
I am new to pybullet. Request your help to solve the below issue

I am building a quadruped robot where each leg has 3 joint (motors). 2 at the hip and 1 at keen joint.
When I run the below code 2 hip joint joints move (rotate) at the same time.

Is it possible to rotate the joints one after the other. Ex. Joint 2 starts after Joint 1 finishes its rotation.

Code: Select all

def LegBR(hip,knee):
   motrotvalue = hip
   p.setJointMotorControl2(vision, motor_back_rightR_joint, p.POSITION_CONTROL, targetPosition=motrotvalue, force=maxMotorForce)
   motrotvalue = knee
   p.setJointMotorControl2(vision, knee_back_rightR_joint, p.POSITION_CONTROL, targetPosition=motrotvalue, force=maxMotorForce)
   p.stepSimulation()


def LegBL(hip,knee):
   motrotvalue = hip
   p.setJointMotorControl2(vision, motor_back_leftL_joint, p.POSITION_CONTROL, targetPosition=motrotvalue, force=maxMotorForce)
   motrotvalue = knee
   p.setJointMotorControl2(vision, knee_back_leftL_joint, p.POSITION_CONTROL, targetPosition=motrotvalue, force=maxMotorForce)
   p.stepSimulation()

maxMotorForce = 5000
t = 0
prevTime = time.time()


while (1):
   timeScale = 1.0
   amplitude = 0.4999
   newTime = time.time()
   dt = (newTime - prevTime) * timeScale
   t = t + dt

   prevTime = newTime
   legpos = 0.05

   amp = amplitude
   a = math.sin(t) * amp + legpos
   b = -(math.sin(t) * amp + legpos)
      
   LegBR(a,0)
   LegBL(-b,0)
   #LegFR(a,0)
   #LegFL(b,0)

   p.setGravity(0, 0, -10)
   #time.sleep(1/240)

Image

In the above image both joint 1 and joint 2 start at the same time. I want that joint 2 (motor) to start after joint 1 completes its rotation.

Thank you for your support.
Post Reply