Simple model not working, please help
Posted: Tue Sep 07, 2021 1:50 am
I have created an extremely simple model of a rotor rotating around the z-axis. The base link is a heavy rectangular box, the rotor is a single link representing two opposing rotor blades, and there is a continuous joint with a vertical axis between the links. When I use velocity control of the joint motor, calculating the acceleration and velocity myself based on the applied torque, it works nicely. When I use torque control for the motor, the results seem ridiculous. With a moment of inertia of 0.1512 and an applied torque of 0.0001 Nm, starting from rest, the initial angular acceleration is 150 radians/s^2. This decreases over the first 0.22 seconds to 113 rad/s^2. Then I reverse the torque, resulting in an initial acceleration of -187 rad/s^2, gradually decreasing to -112 rad/s^2 over the next 0.4 seconds. Obviously I must be doing something wrong, but what?
Here is the code:
Here is my URDF model:
Any help would be appreciated. Thx.
Here is the code:
Code: Select all
# disable default velocity control of rotor hub joint
p.setJointMotorControl2(gyro, rotor_joint_index,
controlMode=p.VELOCITY_CONTROL, force=0)
# set maximum velocity of joint
p.changeDynamics(gyro, rotor_joint_index, maxJointVelocity=1000)
#initialize simulation state
istep = 0
dt = 1.0/250.0 # time step = 4 ms
p.setTimeStep(dt)
torque = 0.0001
last_v = 0
while True:
info = p.getJointState(gyro, rotor_joint_index)
v = info[1] # angular velocity from bullet
dv = v - last_v
a = dv/dt
last_v = v
rpm = v*60/(2*math.pi) # rpm from angular velocity
print("time=%.3f(s)," % (istep*dt), "applied torque=%8.5f(Nm)," % (torque), \
"v=%7.3f(rad/s)" % (v), "a=%9.3f(rad/s^2)" % (a))
if v > 30:
torque = -0.0001
elif v < -30:
torque = 0.0001
p.setJointMotorControl2(gyro, rotor_joint_index,
controlMode=p.TORQUE_CONTROL,
force=torque)
p.stepSimulation()
istep = istep + 1
sleep(1/10)
Code: Select all
<link name="base_link">
<visual>
<geometry>
<box size="0.5 0.3 0.1"/>
</geometry>
<origin xyz = "0 0 0" rpy="0 0 0"/>
<material name="blue"/>
</visual>
<collision>
<geometry>
<box size="0.5 0.3 0.1"/>
</geometry>
<origin xyz = "0 0 0" rpy="0 0 0"/>
</collision>
<inertial>
<origin xyz = "0 0 0" rpy="0 0 0"/>
<mass value="100"/>
<inertia ixx="100" ixy="0" ixz="0" iyy="100" iyz="0.0" izz="100"/>
</inertial>
</link>
<link name="rotor">
<visual>
<geometry>
<box size="2 0.05 0.01"/>
</geometry>
<origin xyz="0 0 0.0" rpy="0 0 0"/> <!-- offset of child frame from the joint -->
<material name="black"/>
</visual>
<inertial>
<origin xyz="0 0 0.0" rpy="0 0 0"/>
<mass value="1"/>
<inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.1512"/>
</inertial>
</link>
<joint name="base_to_hub" type="continuous">
<parent link="base_link"/>
<child link="rotor"/>
<axis xyz="0 0 1"/> <!-- vector of the axis of rotation -->
<origin xyz="0 0 0.2" rpy="0 0 0"/> <!-- transform from parent frame to child frame -->
</joint>