Trying to store force values with associated postion values

asked 2021-07-27 12:06:02 -0500

PGTKing gravatar image

Hello community, I am working with the rrbot arm and am trying to run a python script that will store the force value that I give to the first joint of the arm in an array and the real time associated positional data of the first joint of the arm in an array.

Here is my code

class Robotreacher2:
def __init__(self):
    rospy.init_node('robot_control_node', anonymous=True)
    self.talker = rospy.Publisher('/rrbot/joint1_position_controller/command', Float64, queue_size=10)
    rospy.Subscriber('/rrbot/joint_states', JointState, self.joint_callback)
    self.force = None
    self.rate = rospy.Rate(1)
    while not rospy.is_shutdown():
        self.give_force()
        self.rate.sleep()
        #print(self.force)


def give_force(self):
    self.force =  random.randrange(-8, 8, 1)
    self.talker.publish(self.force)
    print("the force is ", self.force)
    return self.force

def joint_callback(self, data):
    #print(data)
    joint = abs(data.position[0])%(2*math.pi)
    #print("joint position is", joint)
    return joint

def robotcontrolloop2():

i=0
training_samplex, training_sampley = [], []
while i < 10:
    r=Robotreacher2()
    training_samplex.append(r.give_force())
    training_samplex.append(r.joint_callback(data))
    if r.give_force is not None:
        i += 1
print(training_samplex, training_sampley)

robotcontrolloop2()

edit retag flag offensive close merge delete