mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-06 04:14:09 +05:30
Finished tweaks on follow_controller.py to execute joint action trajectories
This commit is contained in:
parent
d9968a7f4b
commit
6d6390fa53
@ -116,6 +116,10 @@ class FollowController(Controller):
|
|||||||
if start.secs == 0 and start.nsecs == 0:
|
if start.secs == 0 and start.nsecs == 0:
|
||||||
start = rospy.Time.now()
|
start = rospy.Time.now()
|
||||||
|
|
||||||
|
# Set the start time for each joint
|
||||||
|
for i in range(len(self.joints)):
|
||||||
|
self.device.joints[self.joints[i]].time_move_started = start
|
||||||
|
|
||||||
r = rospy.Rate(self.rate)
|
r = rospy.Rate(self.rate)
|
||||||
last = [ self.device.joints[joint].position for joint in self.joints ]
|
last = [ self.device.joints[joint].position for joint in self.joints ]
|
||||||
for point in traj.points:
|
for point in traj.points:
|
||||||
@ -138,8 +142,12 @@ class FollowController(Controller):
|
|||||||
last[i] += cmd
|
last[i] += cmd
|
||||||
self.device.joints[self.joints[i]].time_move_started = rospy.Time.now()
|
self.device.joints[self.joints[i]].time_move_started = rospy.Time.now()
|
||||||
self.device.joints[self.joints[i]].in_trajectory = True
|
self.device.joints[self.joints[i]].in_trajectory = True
|
||||||
|
self.device.joints[self.joints[i]].is_moving = True
|
||||||
self.device.joints[self.joints[i]].desired = last[i]
|
self.device.joints[self.joints[i]].desired = last[i]
|
||||||
else:
|
else:
|
||||||
|
self.device.joints[self.joints[i]].speed = 0.0
|
||||||
|
self.device.joints[self.joints[i]].in_trajectory = True
|
||||||
|
self.device.joints[self.joints[i]].is_moving = False
|
||||||
velocity[i] = 0
|
velocity[i] = 0
|
||||||
r.sleep()
|
r.sleep()
|
||||||
return True
|
return True
|
||||||
|
@ -36,7 +36,6 @@ class Joint:
|
|||||||
|
|
||||||
self.position = 0.0 # radians
|
self.position = 0.0 # radians
|
||||||
self.start_position = 0.0
|
self.start_position = 0.0
|
||||||
self.goal_position = 0.0
|
|
||||||
self.position_last = 0.0 # radians
|
self.position_last = 0.0 # radians
|
||||||
self.velocity = 0.0 # rad/s
|
self.velocity = 0.0 # rad/s
|
||||||
self.servo_speed = 0.0 # rad/s
|
self.servo_speed = 0.0 # rad/s
|
||||||
@ -144,9 +143,6 @@ class Servo(Joint):
|
|||||||
# Record the starting position
|
# Record the starting position
|
||||||
self.start_position = self.get_current_position()
|
self.start_position = self.get_current_position()
|
||||||
|
|
||||||
# Record the goal_postion
|
|
||||||
self.goal_position = msg.data
|
|
||||||
|
|
||||||
# Set the target position for the next servo controller update
|
# Set the target position for the next servo controller update
|
||||||
self.desired = msg.data
|
self.desired = msg.data
|
||||||
|
|
||||||
@ -280,24 +276,6 @@ class ContinousServo(Joint):
|
|||||||
self.is_moving = True
|
self.is_moving = True
|
||||||
self.direction = copysign(1, self.desired - self.position)
|
self.direction = copysign(1, self.desired - self.position)
|
||||||
|
|
||||||
# def command_cb(self, msg):
|
|
||||||
# # Check limits
|
|
||||||
# if msg.data > self.max_speed:
|
|
||||||
# msg.data = self.max_speed
|
|
||||||
#
|
|
||||||
# if msg.data < self.min_speed:
|
|
||||||
# msg.data = self.min_speed
|
|
||||||
#
|
|
||||||
# # Adjust for the neutral offset
|
|
||||||
# if self.invert:
|
|
||||||
# servo_ticks = self.neutral - msg.data * self.ticks_per_rad_per_sec
|
|
||||||
# else:
|
|
||||||
# servo_ticks = self.neutral + msg.data * self.ticks_per_rad_per_sec
|
|
||||||
#
|
|
||||||
# # Set the target speed for the next servo controller update
|
|
||||||
# self.desired = radians(servo_ticks)
|
|
||||||
|
|
||||||
|
|
||||||
class ServoController():
|
class ServoController():
|
||||||
def __init__(self, device, name):
|
def __init__(self, device, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -317,6 +295,7 @@ class ServoController():
|
|||||||
if rospy.Time.now() > self.next_update:
|
if rospy.Time.now() > self.next_update:
|
||||||
for servo in self.servos:
|
for servo in self.servos:
|
||||||
|
|
||||||
|
|
||||||
# Check to see if we are within 2 degrees of the desired position or gone past it
|
# Check to see if we are within 2 degrees of the desired position or gone past it
|
||||||
if not servo.in_trajectory and servo.is_moving:
|
if not servo.in_trajectory and servo.is_moving:
|
||||||
if abs(servo.position - servo.desired) < radians(2.0) or copysign(1, servo.desired - servo.position) != servo.direction:
|
if abs(servo.position - servo.desired) < radians(2.0) or copysign(1, servo.desired - servo.position) != servo.direction:
|
||||||
@ -329,6 +308,7 @@ class ServoController():
|
|||||||
if servo.is_moving:
|
if servo.is_moving:
|
||||||
try:
|
try:
|
||||||
# Get the interpolated current position of the servo
|
# Get the interpolated current position of the servo
|
||||||
|
servo.position = servo.get_interpolated_position()
|
||||||
if not servo.in_trajectory:
|
if not servo.in_trajectory:
|
||||||
servo.position = servo.get_interpolated_position()
|
servo.position = servo.get_interpolated_position()
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user