Hi! I’ve just started working with Dynamixel motors using pypot, and my aim is to get the motors to follow a trajectory. It is critical that the velocity and position trajectories are followed as closely as possible. Here’s the code I’m using:
import pypot.dynamixel.io
import pypot.dynamixel.error
import pypot.dynamixel.motor
import pypot.dynamixel.controller
import pypot.robot
import matplotlib.pyplot as plt
robot = pypot.robot.from_json('robot_config.json')
#setting motors to 0
for m in robot.motors:
m.moving_speed=0
m.goal_position=0
time.sleep(3)
amp=30
freq=0.5
t = numpy.arange(0, 10, 0.01)
#follow this trajectory
speeds = amp * numpy.cos(2 * numpy.pi * freq * t)
desired_positions = amp*numpy.sin(2*numpy.pi * freq * t) / (2*numpy.pi*freq)
positions = []
velocities = []
for s,p in map(None,speeds,desired_positions):
robot.motors[0].moving_speed = s
robot.motors[0].goal_position=p
positions.append(robot.motors[0].present_position)
velocities.append(robot.motors[0].present_speed)
time.sleep(0.01)
plt.plot(t,velocities)
plt.show()
When I plot the velocity, here’s what I get:
Is this a sensor error? Or am I doing something fundamentally wrong?
PS: I can’t use goal_speed because I need control over speed at every instant of time. I have also tried using a while loop to move with a speed till a point is reached (bypassing time.sleep() altogether), but those results are no good either.
OK, it is nominal. The delay you see between what you want and what you have is something you cannot reduce.
Concerning the derivative, it is computed doing the differential of the position. The consequence is that any noise on position is amplified by derivation as you can see.
For me, you cannot have better.
What motor is it? If you have one with PID control, you can tune it to have better performances.
The PID is applied on position control.
You cannot command the speed (except limiting it).
Therefore, the problem is that you want to follow a ramp input. I advise you to test your PID tuning on a triangle input instead of a sinus. The integral term will help you to follow this ramp but you should have 2 integrators to follow exactly the ramp.