Hey guys I am trying to get access to the joint value from my class that I setup but it has been pain to extract and don't know how to. here is my code
class Robotreacher:
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.joint1 = 0
self.target1 = random.randint(10, 62)/10
self.start_time = time.time()
self.rate = rospy.Rate(1)
self.reward = None
print("the target is", self.target1)
print("the reward is", self.reward)
while self.observation_check() is False:
self.give_force()
self.rate.sleep()
def give_force(self):
self.force = random.randrange(-8, 8, 1) # Changes force every time, right before publishing
self.talker.publish(self.force)
#print("the force is ", self.force)
return self.force
def joint_callback(self, data):
#print(data)
self.joint1 = abs(data.position[0])%(2*math.pi)
def observation_check(self):
target2 = self.target1 - 0.2
if target2 < self.joint1 < self.target1:
done = True
else:
done = False
return done
def what_is_reward(self):
#reward = None
if self.observation_check() is True:
self.reward = (time.time() - self.start_time)
return self.reward
print("the reward is", self.reward)
def get_joint(self):
return self.joint1
def robotcontrolloop2(): i=0 training_samplex = [] r = Robotreacher() #w = r.give_force() #print("this is force", w) training_z = []
while i < 5:
z = r.give_force()
p = r.get_joint
print("this joint position is", p)
i += 1
#training_z.append(z)
#print(training_z)
robotcontrolloop2()