How do I detect if the GoPiGo3 is turning in Python?

I want a sound to play only when the robot is turning and have it stop when it stops turning. How do I do this?

1 Like

How do you intend to do this? I mean how do you plan on playing the sound, with pygame?

You could wrap the turn function inside another one which would:

  1. start the sound
  2. do the turn with blocking=true
  3. stop the sound
1 Like

I do not use pygame. I am using a cmd aplay string. IF the sound plays until done, that prevents the robot from stopping the turn.

1 Like

I am using a remote button to turn, so I want the sound to play only while the button is pressed.

1 Like
            while remote.get_remote_code()=="right":
                cmd = '''aplay /home/jupyter/"turn_signal.wav"'''

This code makes the robot turn, and play a sound. I want the sound to play ONLY when the condition is true. I think the best way would be to detect if the robot is turning.

1 Like

I cannot do pygame due to errors. I want to:

  1. Turn
  2. Play the sound until I stop turning (release the button)
1 Like

I don’t think I’m completely following you. When running the code you’ve posted in one of your recent posts, the sound gets played every time the right button (whichever it is) on the remote is pressed. The moment it gets played is also the moment the robot goes to the right.
So, that clearly happens when that condition (of receiving a right command from the remote) is met, so what’s wrong with that?
Isn’t that the desired outcome?
Can you expand on that?

What errors? Can you show us some outputs alongside the code?

1 Like

The sound causes the robot to not stop immediately when releasing the button. I want the sound and the turn to stop immediately when the button is released.

1 Like

How long is your sound byte? That might be a factor too.

1 Like

Well, in that case, I don’t think that’s possible. If my memory helps, the remote control won’t give you back a feedback when the button is released. It only gets detected when it’s pressed. Run the remote.get_remote_control function in a continuous loop and see what happens when you press on a button and then release it.

1 Like

I want the robot to make a turn signal sound, like a car, when the button to turn is pressed, and have the sound stop when released. This sound I modified so I cannot share it. It is 1 second.

1 Like

I try to load the sound, both with path and without, into a pygame.mixer.Sound object. I get something like “Cannot load file” when I run that line, so I can’t even play() it.

1 Like

I’ve done pygame before, and it seems like GoPiGo is just not designed to run pygame.

1 Like

Got it! I used pygame with an ogg file. It seems to not like wav files. So all I had to do is run the wav file through an online wav to ogg converter to get it working again! Now to have the sound stop when the button is released, which I want in my while true loop.



Part of your problem is the larger issue of the GoPiGo not really having any sense of where it is or what it’s doing. There is no real-time geo and/or position sensing so pretty much everything the 'bot does is an estimate.

I have run into the same problem when trying to navigate. Because of this, I’ve picked up a Dexter Industries IMU board and a SparkFun GPS breakout I can try with my 'bot to try to make it more “self aware” of what it is doing.

We’ll see. I have a few other experiments I want to try first.