Need help with ros code
Hi all, I am making a robot that tries the solve the reacher problem made by openai. here is link
Here is my code
#!/usr/bin/env python3
import rospy
from std_msgs.msg import Float64
import math
import random
from sensor_msgs.msg import JointState
import numpy as np
import time
import threading
from std_srvs.srv import Empty
import sys
#start_time = time.time()
#target1 = random.randint(10, 62)/10
reset_simulation = rospy.ServiceProxy('/gazebo/reset_simulation', Empty)
#rospy.init_node('reset_world')
#rospy.wait_for_service('/gazebo/reset_world')
reset_world = rospy.ServiceProxy('/gazebo/reset_world', Empty)
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):
self.joint1 = abs(data.position[0])%(2*math.pi)
#self.joint2 = data.position[1]
#reward = None
#if self.observation_check() is True:
#reward = (time.time() - start_time)
#reset_world()
#reset_simulation()
#sys.exit("restarting simulation")
#return reward
#else:
#pass
#print(self.joint1)
return self.joint1
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 robotcontrolloop():
i=0
training_samplex, training_sampley, training_samplez = [], [], []
while i < 10:
#start_time = time.time()
r = Robotreacher()
r
training_samplex.append(r.give_force())
training_sampley.append(r.joint_callback())
if r.what_is_reward() is not None:
training_samplez.append(r.what_is_reward())
i += 1
'''
if RobotControl() is not None:
reset_world()
'''
robotcontrolloop()
The robot I am getting is
training_sampley.append(r.joint_callback())
TypeError: joint_callback() missing 1 required positional argument: 'data'
I tried inputting data but its not working. Thanks in advance.
Your screen name is offensive and has racist overtones. @gvdhoorn I request that this post be deleted.
I agree. The post itself is not offensive, but the screen name is. @pregnantghettoteen: Please update your screen name ASAP. @gvdhoorn@tfoote : What should we do with this post in the meantime? (BTW: I just edited code block formatting just now, wording is unchanged)
@Mike Scheutzow The username is a reaction to overly pc world which I think is detrimental to free speech, I use it for all my social media websites. I understand this is a private website so, will change it according to the rules set by the mods. This is my one a only rebuttle, if you still want me to change my username, please let me know.
Yes, I would like you to change your username. Thank you.
I also agree with @Mike Scheutzow and @Martin Günther
@pregnantghettoteen: It has been 7 days, and you have still not changed your user name. Please do so immediately, otherwise I will remove your post in 2 days. I get it that it was not meant to be racist, but it makes people uncomfortable, and I think it is not overly PC to ask you to change it. Thank you.
@Martin Günther changed
Thank you!