ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Why isnt my loop finishing? Seeing others see what Im not

asked 2021-11-05 17:16:28 -0500

PGTKing gravatar image

when I comment out this loop the program runs fine

    def what_is_reward(self):
    start_time = time.time()
    time_in_right_position = 0
    while self.target1 - 1.0 < self.joint1 < self.target1 + 1.0:
        time_in_right_position = time.time() - start_time

This loop runs inside this loop, too make the problem more clear

        while True:
        current_time = time.time()
        elapsed_time = current_time - start_time
        z = r.give_force()
        print("z is", z)
        k = r.get_joint()
        print("target during game is", g)
        print("the joint position is", k)
        score += r.what_is_reward()
        print("the score during game is", score)
        #i +=1
        if elapsed_time > seconds:
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-05 23:16:49 -0500

billy gravatar image

Is there anyway for self.joint1 to update once it's in that while loop? Looks like infinite loop to me once it gets entered. There is no way to update the exit variable.

What have you tried in your effort to diagnose the issue?

edit flag offensive delete link more


Hey, thanks for looking into my question, self.joint does change while the simulation is running. All I have done was made sure that this loop was the one that was stopping the simulation, I also checked your reasoning and self.joint1 does update while inside the while loop.

PGTKing gravatar image PGTKing  ( 2021-11-08 15:38:15 -0500 )edit

Does it ever fail the "self.target1 - 1.0 < self.joint1 < self.target1 + 1.0" condition?

Out of couriosity, how does it update while in that loop when "k = r.get_joint()" is not in that loop?

billy gravatar image billy  ( 2021-11-08 16:20:12 -0500 )edit

figured it out, my force function would act in such a way sometimes that it would give the perfect amount of force where the arm would be stuck between the two targets, Causing the while loop to be infinite, if I made the target area small enough the joint would pass through it causing the loop to break, then applying another force to the joint allowing the outer loop to continue.

PGTKing gravatar image PGTKing  ( 2021-11-08 18:11:23 -0500 )edit

Glad you solved it, but still wondering how you update the joint variable while you're in the loop. Is self.joint1 not related to r.get_joint?

billy gravatar image billy  ( 2021-11-08 20:15:40 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-11-05 17:16:28 -0500

Seen: 48 times

Last updated: Nov 05 '21