ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

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

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)
        time.sleep(1.7)
        print(elapsed_time)
        #i +=1
        if elapsed_time > seconds:
            break
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Comments

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 85 times

Last updated: Nov 05 '21