def check_pick(file_name, diff_values):
    fullData = ParseLogFile(file_name, '', 0,
                            'vrep/ver5').getFullDataWithoutBelief()
    final_state = fullData['stepInfo'][-1]['state']
    final_reward = fullData['stepInfo'][-1]['reward']
    final_action = ("").join(
        fullData['stepInfo'][-1]['action'][:-1].split(" "))
    distance = 0
    if (final_action == '-Action=ActionisPICK'):

        distance = math.pow(final_state.g_x - final_state.o_x + diff_values[0],
                            2)
        distance = distance + math.pow(
            final_state.g_y - final_state.o_y + diff_values[1], 2)
        distance = distance + math.pow(
            final_state.g_z - final_state.o_z + diff_values[2], 2)
        distance = math.pow(distance, 0.5)
        if (distance > 0.12):
            calculated_reward = -10
        else:
            calculated_reward = 100

    else:
        calculated_reward = final_reward
    return [calculated_reward, final_reward, distance]
def test_parsing_methods(filename):

    fullData1 = ParseLogFile(filename, '', -1, 'toy',
                             1).getFullDataWithoutBelief()
    seqs1 = []
    process_full_data(fullData1, seqs1)

    fullData2 = ParseLogFile(filename, '', -1, 'toy',
                             2).getFullDataWithoutBelief()
    seqs2 = []
    process_full_data(fullData2, seqs2)

    assert len(seqs1[0]) == len(seqs2[0])
    for i in range(0, len(seqs1[0])):
        assert seqs1[0][i][0] == seqs2[0][i][0]
        for j in range(0, len(seqs1[0][i][1])):
            assert seqs1[0][i][1][j] == seqs2[0][i][1][j]
    print seqs2
    print seqs1
def parse_file(file_name,
               belief_type='',
               isTraining=True,
               round_no=0,
               state_type='toy'):

    if not isTraining:
        round_no = -1
    fullData = ParseLogFile(file_name, belief_type, round_no,
                            state_type).getFullDataWithoutBelief()
    seqs = []
    process_full_data(fullData, seqs, state_type, isTraining)
    return seqs
Exemple #4
0
def main():

    featureId = '5'
    logType = 'learning'
    if len(sys.argv) > 1:
        featureId = sys.argv[1]
    if len(sys.argv) > 2:
        logType = sys.argv[2]

    successfulTestCases = []
    failureTestCases = []

    for i in range(0, 400):

        #logfileName = '/home/neha/WORK_FOLDER/phd2013/phdTopic/despot/despot-0.2-server-version/4_objects_obs_prob_change_particles_as_state/adaboost_different_objects/grasping_v' + featureId + '/state_' + repr(i) + '.log'
        #logfileName = '/home/neha/WORK_FOLDER/phd2013/phdTopic/despot/despot-0.2-server-version/4_objects_obs_prob_change_particles_as_state/adaboost_different_objects/sensor_observation_sum/state_' + repr(i) + '.log'
        #logfileName = '/home/neha/WORK_FOLDER/phd2013/phdTopic/despot/despot-0.2-server-version/4_objects_obs_prob_change_particles_as_state/deepLearning_different_objects/version3/state_' + repr(i) + '.log'
        logfileName = '/home/neha/WORK_FOLDER/ncl_dir_mount/neha_github/autonomousGrasping/graspingV4/results/despot_logs/t1_n20/Toy_test_belief_default_t1_n20_trial_' + repr(
            i) + '.log'

        #logfileName = '/home/neha/WORK_FOLDER/phd2013/phdTopic/despot/despot-0.2-server-version/4_objects_obs_prob_change_particles_as_state/adaboost_different_objects' + '/state_' + repr(i) + '.log'
        #logfileName = '/home/neha/WORK_FOLDER/phd2013/phdTopic/despot/despot-0.2-server-version/4_objects_obs_prob_change_particles_as_state/graspingV4_state_' + repr(i) + '_t10_obs_prob_change_particles_as_state_4objects.log'
        #logfileName = '/home/neha/WORK_FOLDER/phd2013/phdTopic/despot/despot-0.2-server-version/4_objects_obs_prob_change_particles_as_state/graspingV3_state_' + repr(i) + '_t20_obs_prob_change_particles_as_state_4objects.log'
        logParser = ParseLogFile(logfileName, '')
        if (len(logParser.stepInfo_) < 90):
            successfulTestCases.append(logParser)
        else:
            failureTestCases.append(logParser)

    app = QApplication([])
    currentState = MainWindow(successfulTestCases, failureTestCases)

    #circles2 = DrawCircles()
    currentState.show()
    #circles2.show()
    app.exec_()
def get_log_file_parser(log_filename):
    lfp = ParseLogFile(log_filename, 'vrep', 0, 'vrep')
    return lfp
        msg.observation = touch_0 * 2 + touch_1

    return msg


if __name__ == '__main__':

    log_filename = sys.argv[1]

    pub_gripper = rospy.Publisher('gripper_pose', State, queue_size=10)
    pub_belief = rospy.Publisher("object_pose", Belief, queue_size=10)
    rospy.init_node('python_belief_state_publisher')
    rate = rospy.Rate(10000)
    rate.sleep()

    lfp = ParseLogFile(log_filename, 'vrep', 0, 'vrep')

    for i in range(0, len(lfp.stepInfo_)):
        if i == 0:
            state_value = lfp.roundInfo_['state']
            touch_0 = 0
            touch_1 = 0
        else:
            state_value = lfp.stepInfo_[i - 1]['state']
            touch_0 = lfp.stepInfo_[i - 1]['obs'].sensor_obs[0]
            touch_1 = lfp.stepInfo_[i - 1]['obs'].sensor_obs[1]

        p_State = getPublishableState(state_value, touch_0, touch_1)
        p_Belief = getPublishableBelief(lfp.stepInfo_[i]['belief'])
        pub_gripper.publish(p_State)
        pub_belief.publish(p_Belief)
    def __init__(self, logfileName, drawPlanningBelief=True, parent=None):
        QWidget.__init__(self, parent)
        # setGeometry(x_pos, y_pos, width, height)
        self.setGeometry(300, 300, 1300, 700)
        self.setWindowTitle('Main')
        self.drawPlanningBelief = drawPlanningBelief

        self.nextButton = QPushButton('Next', self)
        self.nextButton.clicked.connect(self.handleNextButton)

        self.prevButton = QPushButton('Prev', self)
        self.prevButton.clicked.connect(self.handlePrevButton)

        self.playButton = QPushButton('Play', self)
        self.playButton.clicked.connect(self.handlePlayButton)

        self.playButtonState = 0
        self.playButtonTimers = [
            threading.Timer(1, self.playTimer),
            threading.Timer(1, self.playTimer)
        ]
        self.currentTimer = 0

        belief_type = ''
        if drawPlanningBelief:
            belief_type = 'planning'
        self.logParser = ParseLogFile(logfileName, belief_type)
        self.stateWindow = DrawState(self.logParser, self)
        if self.drawPlanningBelief:
            self.beliefWindow = DrawPlanningBelief(self.logParser, self)
        else:
            self.beliefWindow = DrawLearningBelief(self.logParser, self)

        self.messageWindow = QWidget(self)
        self.messageWindow.setMaximumSize(200, 600)
        actionLayout = QVBoxLayout(self.messageWindow)
        scroll = QScrollArea(self)
        scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        scroll.setWidgetResizable(True)
        scroll.setWidget(self.messageWindow)

        self.currentStepLabel = QLabel(
            'Current Step: ' + repr(self.stateWindow.step) + '/' +
            repr(len(self.logParser.stepInfo_)), self)
        self.currentActionLabel = QLabel('Action: ', self)
        self.nextActionLabel = QLabel(
            '0:' + self.logParser.stepInfo_[0]['action'][20:], self)
        actionLayout.addWidget(self.currentStepLabel)
        actionLayout.addWidget(self.currentActionLabel)
        actionLayout.addWidget(self.nextActionLabel)

        #actionLayout.addWidget(QLabel('Actions', self))
        self.actionLabels = []
        for i in range(0, len(self.logParser.stepInfo_)):
            actionText = repr(
                i) + ":" + self.logParser.stepInfo_[i]['action'][20:]
            self.actionLabels.append(QLabel(actionText, self))
            #actionLayout.addWidget(self.actionLabels[i])

        layout = QVBoxLayout(self)

        hLayout = QHBoxLayout(self)
        hLayout.addWidget(self.messageWindow)
        hLayout.addWidget(self.stateWindow)
        hLayout.addWidget(self.beliefWindow)

        hLayoutB = QHBoxLayout(self)
        hLayoutB.addWidget(self.playButton)
        hLayoutB.addWidget(self.prevButton)
        hLayoutB.addWidget(self.nextButton)

        layout.addLayout(hLayout)
        layout.addLayout(hLayoutB)