beginner at reinforcement learning need help with code
I'm trying to print the reward, but nothing is printing on the terminal
here is my code
#!/usr/bin/env python3
# license removed for brevity
import rospy
from std_msgs.msg import Float64
import math
import random
from sensor_msgs.msg import JointState
import numpy as np
import time
###from keras.models import Sequential
###from keras.layers import Dense, Dropout
start_time = time.time()
class RobotControl():
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 # Generally, it's good to initialize member variables. What if callback() is called before give_force()?
rate = rospy.Rate(10)
while not rospy.is_shutdown():
self.give_force()
rate.sleep()
def give_force(self):
self.force = random.choice([-2,2]) # Changes force every time, right before publishing
self.talker.publish(self.force)
def joint_callback(self, data):
self.joint = data.position[0]
def observation_check(self):
max_height = -3.2
if (self.joint < max_height):
done = True
else:
done = False
return done
def get_reward_for_observations(done):
if done == True:
reward = (time.time() - start_time)
else:
pass
print(reward)
def robot_arm_system_test():
robotcontrol()
done = robotcontrol.observation_check()
reward = robotcontrol.get_reward(done)
print(reward)
if __name__=="__main__":
robot_arm_system_test()
Are you only running this code? The
get_reward_for_observations
that is executingprint
doesn't seem to be called from anywhere.fix your formatting and first do some debuggin yourself please, your robotcontrol class doesn't have a function 'get_reward'. also passing a 'done' function parameter is not required, and bad practise, just don't execute that function