XBox button debouncing
Hey,
I want to implement button debouncing for my xbox controller and I couldn't find anything much helpful till now. All the info that is available on google is related to microcontrollers. Is there an option or a way button debouncing can be implemented in a ros python code?
Thanks in advance
Edit:
@PeteBlackerThe3rd In the pic you can see that the joint changed once, when I gave the input through the controller, but instead of stopping at the first 'Plan complete', the loop ran for 7 more times, which causes a bit of delay in processing the second instruction given through the controller. Could you maybe point out my mistake or maybe guide me through the right process so that I can detect my mistake?
Edit-2 Code screenshot: I know it's not suggested to take a screen shot of the code and post it here, but I just wanted to make sure that the indentations I am having in my code are clear, since indentations are a not always correct here
Edit -2
This is my code
#!/usr/bin/env python
import sys
import copy
import rospy
import moveit_commander
from moveit_msgs.msg import *
from geometry_msgs.msg import *
from sensor_msgs.msg import *
import time
j1 = 0
a = 0
flag1 = 0
flag2 = 0
def callback(data, group1):
global a, flag1, flag2, j1
if ((data.buttons[0]==1) and (data.axes[6]==1)):
if (flag1 == 0):
a += 1
flag1 = 1
j1 = (int(a))*0.1
print "Value of Joint 1 is: %s " %j1
if (j1 >= 3.1):
group1_variable_values[0] = 3.1
print "Limit reached joint 1"
else:
print "changing joint 1"
print "Plan completed"
group1_variable_values[0] = j1
group1.set_joint_value_target(group1_variable_values)
plan2 = group1.plan()
execute2= group1.execute(plan2)
rospy.sleep(1)
print "plan complete"
else:
flag1 = 0
def move_group_python_interface():
global group1_variable_values, robot
moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node('move_group_python_interface', anonymous=True)
robot = moveit_commander.RobotCommander()
group1 = moveit_commander.MoveGroupCommander("igus_planning")
group1_variable_values = group1.get_current_joint_values()
display_trajectory_publisher = rospy.Publisher('/move_group/display_planned_path',
moveit_msgs.msg.DisplayTrajectory,queue_size=50)
rospy.Subscriber("joy", Joy, callback, callback_args=group1)
rospy.spin()
if __name__=='__main__':
try:
move_group_python_interface()
except rospy.ROSInterruptException:
pass
The buttons on the Xbox controller are already de-bounced. This is a low level process performed by hardware not a function performed by software.
Can you show the source code of your node which is taking the controller input and interfacing with MoveIt, then we'll be able to see what's going on.
If you are responding to joy messages where the button is pressed, then it is expected for there to be many of these for a single key press. If there were hundreds of messages with the button going on and off, then this would be a de-bouncing problem.
You may be able to fix this by detecting the transition from off to on to trigger your plan, so called edge triggering, instead of just checking if the button is pressed (if that is what you're doing)
I edited my previous comment with the code, and you actually did suggest me the edge triggering before and I did apply it. You can check in the code
@Kashyap.m94: do not post extra information as an answer, unless you are answering your own question. I've merged your answer into your original question text, but please keep this in mind.
You've been asked this before, so it would be appreciated if you could follow forum etiquette.