Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added claw control - Ayush #13

Open
wants to merge 2 commits into
base: arm-controls
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion arm_control/arm_control/human_arm_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,51 @@ def move_joint(joystick_input, cur_angle, index):

#sets the waists angle to be at the limit if it exeeds the limit
cur_angle[index] = max(joint_lower_limits[index], min(cur_angle[index], joint_upper_limits[index]))
return cur_angle
return cur_angle

def claw_control(joystick_input, cur_angle, curr_opening):
"""
This function takes in the angle of the motor and the opening of claw,
and returns how much the claw opens up with joystick input
"""
#finding the change angle of opening
#the limits of the angle must be changed in joint limit
angle_change = speed * joystick_input * joint_max_speed[hand_index]


#when the angle is at 2pi, we assume that the opening change is 1 inch
#Also assuming the max opening to 5 inches for now
one_turn_change = 1
open_max = 5
open_min = 0

# In the case that the motor has reaches its limits in terms or rotation angle
if cur_angle[hand_index] + angle_change >= joint_upper_limits[hand_index]:
return open_max

if cur_angle[hand_index] + angle_change <= joint_lower_limits[hand_index]:
return open_min

#set the new change in opening proportionally
open_change = (angle_change*one_turn_change)/(2*np.pi)
new_opening = curr_opening + open_change
#ensures that new opening is not too big or small
new_opening = max(open_min, min(new_opening, open_max))
return new_opening


print(claw_control(-0.1, np.full(5,np.pi), 1)) #good case

print(claw_control(0.1, np.full(5,np.pi), 1)) #upper bound on angle case, fully opens

print(claw_control(-0.1, np.full(5,-np.pi), 1)) #lower bound on angle case, fully closes

print(claw_control(-0.1, np.full(5,0.3*np.pi), 0)) #lower bound on opening case, fully closes

print(claw_control(0.1, np.full(5,0.3*np.pi), 5)) #upper bound on opening case, fully opens