Zackeos
Posts: 1
Joined: Sun Feb 02, 2020 9:41 pm

Help with Build a robot buggy project

Sun Feb 02, 2020 10:11 pm

When I follow the steps and run the code:
from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10)
And the in the shell run:
robby.forward()
I get the error:
NameError: 'robby' is not defined

Can anyone help?

User avatar
B.Goode
Posts: 10191
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Help with Build a robot buggy project

Mon Feb 03, 2020 6:22 am

Zackeos wrote:
Sun Feb 02, 2020 10:11 pm
When I follow the steps and run the code:
from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10)
And the in the shell run:
robby.forward()
I get the error:
NameError: 'robby' is not defined

Can anyone help?


The robby.forward() function call is a Python statement that must be part of the same Python script as the one that created an instance of Robot()

Using that statement from a separate shell is a complete misunderstanding of what is possible

Your Python script seems to be missing a closing bracket )

User avatar
B.Goode
Posts: 10191
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Help with Build a robot buggy project

Mon Feb 03, 2020 2:46 pm

Subsequent followup -


Possibly the resource you are using is https://projects.raspberrypi.org/en/pro ... -a-buggy/3



So maybe it is a python shell you are using, not a system command line shell?


The inability to use the robby object is probably a consequence of the typing error when you tried to create it.

rifle37
Posts: 1
Joined: Thu May 07, 2020 2:10 am

Re: Help with Build a robot buggy project

Thu May 07, 2020 2:17 am

Zackeos wrote:
Sun Feb 02, 2020 10:11 pm
When I follow the steps and run the code:
from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10)
And the in the shell run:
robby.forward()
I get the error:
NameError: 'robby' is not defined

Can anyone help?
I am having this same problem. The syntax is correct and it even executes in mu. Unfortunately I can't get it to work in the Python shell. Does anyone know of a way to fix this problem?

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Help with Build a robot buggy project

Thu May 07, 2020 8:30 am

rifle37 wrote:
Thu May 07, 2020 2:17 am
I am having this same problem. The syntax is correct and it even executes in mu. Unfortunately I can't get it to work in the Python shell. Does anyone know of a way to fix this problem?
Same problem as above, have you tried the suggested solution? Don't try to run the commands from the command shell or python shell just add them to the python script.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
B.Goode
Posts: 10191
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Help with Build a robot buggy project

Thu May 07, 2020 8:32 am

Welcome to the Raspberry Pi forums -

rifle37 wrote:
Thu May 07, 2020 2:17 am
Zackeos wrote:
Sun Feb 02, 2020 10:11 pm
When I follow the steps and run the code:
from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10)
And the in the shell run:
robby.forward()
I get the error:
NameError: 'robby' is not defined

Can anyone help?
I am having this same problem. The syntax is correct and it even executes in mu. Unfortunately I can't get it to work in the Python shell. Does anyone know of a way to fix this problem?

The answer remains the same -
The inability to use the robby object is probably a consequence of the typing error when you tried to create it.

JV1
Posts: 1
Joined: Tue May 19, 2020 11:30 am

Re: Help with Build a robot buggy project

Tue May 19, 2020 11:40 am

Hi, we are having the same problem. I have checked syntax and all is correct as per instructions. Does anyone have a solution to this one yet? python code runs in mu. get the same error as others in the terminal as below

pi@raspberrypi:~ $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> robby.forward()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'robby' is not defined
>>>

really appreciate some help as we are new to this.

User avatar
B.Goode
Posts: 10191
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Help with Build a robot buggy project

Tue May 19, 2020 2:26 pm

JV1 wrote:
Tue May 19, 2020 11:40 am
Hi, we are having the same problem. I have checked syntax and all is correct as per instructions. Does anyone have a solution to this one yet? python code runs in mu. get the same error as others in the terminal as below

pi@raspberrypi:~ $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> robby.forward()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'robby' is not defined
>>>

really appreciate some help as we are new to this.



Does anyone have a solution to this one yet?

Yes. The solution has been given or referred to repeatedly in this thread.

Fix the broken syntax in the line robby = Robot(left=(7,8), right=(9,10)

Then you should find that the object 'robby' IS defined and no error will ensue.


Hint: count the brackets...

User avatar
rpiMike
Posts: 1340
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Help with Build a robot buggy project

Tue May 19, 2020 2:55 pm

The 'Build a robot buggy' project has bad instructions !

https://projects.raspberrypi.org/en/pro ... -a-buggy/2

It tells you to write the following code in 'mu' :

Code: Select all

from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10))
Then in a terminal window it tells you to enter Python then robby.forward() which will not work as robby is created in a different environment.

Either enter robby.forward() in the lower section of 'mu' next to >>> or just add it as the third line of code:

Code: Select all

from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10))
robby.forward()
I've twice submitted feedback on this tutorial, but not fixed yet.

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Help with Build a robot buggy project

Tue May 19, 2020 3:00 pm

rpiMike wrote:
Tue May 19, 2020 2:55 pm
The 'Build a robot buggy' project has bad instructions !
They are Buggy instructions :lol:

Return to “Troubleshooting”