[SOLVED] GoPiGo3 code not working - robot not moving

gopigo

#1

My GoPigo connects to my computer and the demo works but when I go to use python and input the right code the robot doesn’t do move. What do you suggest to do?


#2

Hello @gianmcosta

I’ve taken the liberty of erasing your other post, as they are the same issue.

In order to better help you out, can you let us know if you have a GoPiGo3, (red board on top) or a GoPiGo2 (green board on top)?

And can you post an example of the code you’re trying to run?

Last, are you using DexterOS or Raspbian for Robots?

Thank you for those extra details.

Cleo


#3

I’ve been having issues myself with my GoPiGo3. I couldn’t get the motors to turn. The issues seemed to fix itself though. However @cleoqc the hardware test didn’t work for me, but my GoPiGo3 is fully functionaly. Just throwing this info out hoping it will help.


#4

The motors will not run if the batteries are not connected, or if they’re too low.

How did the hardware test fail? Was your firmware up to date?


#5

I am having the same problem as OP. I have code written that works fine on the GoPiGo with RPi 2, but not on the latest RPi 3 model. Have there been changes to the class calls for making the motors go? My program compiles and runs just fine, and the terminal displays the correct output indictating the program is working as intended, it is just not communicating properly to the motors somehow.

I have also tried the test programs provided, and found them to work as intended. It is something in my code I suppose.


#6

Hi @mahydraal,

I’m going to ask the same question Nicole asked: do you use DexterOS or are you running this on Raspbian For Robots?

Anyhow, can you show us the code you’re trying to run?

As far as I remember, there haven’t been significant changes to the class methods, but please, show us what you’re trying to run.

Cheers!


#7

I am running DexterOS, as I believe it is the system that came with the flashdrive in the Base kit.

The code I am trying to run looks something like

It is long. I suppose the part specific to the go pi go would be the motor control function around line 4783.


#8

Thanks @LynnMT
It looks like you are trying to use the library meant for the GoPiGo, and not the GoPiGo3. I’m assuming you do have a GoPiGo3 as you mention DexterOS and the base kit.

For use with a GoPiGo3, your import should look like one of these:
from easygopigo3 import *
Or
from gopigo3 import *

We have detailed documentation for the easygopigo3 library here..


#9

Great stuff thank you.

I will be sure to make some changes.


#10

The code you linked is 3 years old. It was written for our previous GoPiGo model. That’s the reason behind your issue.

Please let us know when you get it working!

Cleo


#11

Oi! I have corrected all the parts that have changed, fixed the imports and tried again.

Now I get this error

-----------------------------------------------------------------------------
File" GoPiGoConnectome.py" , line 4876 in <module>
     set_speed(120)
NameError: name 'set_speed' is not defined.

----------------------------------------------------------------------------

Looking through the documentation…

  def set_speed(self, in_speed):
        """
        | This method sets the speed of the `GoPiGo3`_ specified by ``in_speed`` argument.
        | The speed is measured in *DPS = degrees per second* of the robot's wheel(s).

        :param int in_speed: The speed at which the robot is set to run - speed between **0-1000** DPS.

        .. warning::

             **0-1000** DPS are the *preferred* speeds for the `GoPiGo3`_ robot.
             The speed variable can be basically set to any positive value, but factors like *voltage*, *load*, *battery amp rating*, etc, will determine the effective speed of the motors.

             Experiments should be run by every user, as each case is unique.

        """
        try:
            self.speed = int(in_speed)
        except:
            self.speed = self.DEFAULT_SPEED
        self.set_motor_limits(self.MOTOR_LEFT + self.MOTOR_RIGHT,
                              dps=self.speed)

Clearly it is defined in the gopigo3 and easygopigo3 libraries. what gives?


#12

Hi @LynnMT,

I suspect on line 4876 there’s just the set_speed(120) instruction. If that’s so, then you’re doing it wrong.
You have to instantiate an object of the EasyGoPiGo3 class and then call the method of it like so:

from easygopigo3 import EasyGoPiGo3

robot = EasyGoPiGo3()

robot.set_speed(120)
robot.forward()

# more code

Hope this solves your issue.

Thank you!


#13

I assume I will have to make the same instantiation for every call to the original motor control functions?

robot.left()
robot.right()
robot.stope()
robot.forward()

etc…


#14

Hi @LynnMT,

You’re entirely correct. That’s objected-oriented programming.
Keep in mind that the object instantiation is done only once.

Thank you!


#15

lol thank you for all the help. I know I am obtuse.

so to sum it up for people in a TLDR;

gopigo 1 and 2 models use outdated function libraries and need to have their import statements fixed to the latest gopigo3 and easygopigo imports.

All motor control functions relying on said imports need to be fixed from

left()
right()
forward()
backward()
stop()

etc.

to:

robot.left()
robot.right()
robot.forward()
robot.backward()
robot.stop()

after instantiating an object of the EasyGoPiGo class.

Ok.

Thread Closed. Thanks again. Hope it helps future flounders.


#16

This topic was automatically closed after 3 days. New replies are no longer allowed.