Is it possible to run the line follower module in a python 2 virtual environment?

Hi,

I am in the process of using a GoPiGo3 to follow a line and stop at a stop sign. I have written stop sign image recognition code in python 2 and it’s working as I would expect in the python 2 virtual environment. I am attempting to add all necessary libraries in modules so that I can run the line follower module in the virtual environment. I have followed this example > https://forum.dexterindustries.com/t/solved-how-to-install-brickpi3-in-a-virtualenv-in-python/3214/2 < to install GoPiGo, GoPiGo3, RFR Tools and DI_Sensors. I have done my best to replicate the structure of the Dexter module on Raspbian for Robots. See below for a screenshot of the error. I have already imported EasyGoPiGo3() before this screenshot.

39%20PM

When I run it using python 3 (not in a virtual environment) it works as I would expect and follows a black line. However in the python environment I get the error above.

Please let me know if you can help.

Thanks,

Will

Hi @williamfblock,

I haven’t forgot you, it’s just that I have something on my plate that’s very urgent and I don’t want to throw at you some commands that might or might not work.

To answer your big question, yes, you can install the line follower module in a virtual environment.

Thank you!

Sounds great! Whenever you get a chance!

I’d love to run it in my python 2 virtual environment so that I can run it in conjunction with my stop sign image recognition code.

Thanks!

Hi @williamfblock,

Here’s what you have to do to use the package within a virtual environment.

So let’s create the virtual environment and activate it:

virtualenv .venv2 -p python && source .venv2/bin/activate

Then let’s install some dependencies for GoPiGo3/DI-Sensors with RFR_Tools while being in the virtual environment. RFR_Tools has a package necessary for all interfaces between the robot/sensor and the RaspberryPi.

curl -kL dexterindustries.com/update_rfrtools | bash -s -- --bypass-gui-installation  --env-local --install-python-package

Next, let’s curl the installers for the GoPiGo3 and DI-Sensors and modify a parameter inside both scripts.

curl -kL dexterindustries.com/update_gopigo3 > update_gopigo3.sh
curl -kL dexterindustries.com/update_sensors > update_sensors.sh

Go and edit both files here and here and change the assigned value from true to false.

Now let’s run both of them this way:

bash update_gopigo3.sh --bypass-rfrtools --env-local
bash update_sensors.sh --bypass-rfrtools --env-local

And finally, we need to install the following packages with pip:

pip install future RPi.GPIO numpy 

At the end of all these, pip list should give you these installed packages:

Package                            Version
---------------------------------- -------
Package                            Version
---------------------------------- -------
cffi                               1.11.5
Dexter-AutoDetection-and-I2C-Mutex 0.0.0
DI-Sensors                         1.0.0
future                             0.17.1
gopigo3                            1.2.0
Line-Follower                      1.0.0
numpy                              1.15.4
pip                                18.1
pycparser                          2.19
pyserial                           3.4
python-periphery                   1.1.1
RPi.GPIO                           0.6.5
setuptools                         40.6.2
smbus-cffi                         0.5.1
spidev                             3.2
wheel                              0.32.3

At the end of this, importing, instantiating and playing with the line follower sensor will work. One thing to remember is that line follower is not part of the GoPiGo3 package, but part of DI-Sensors. That’s why DI-Sensors also has to get installed. We are not that clear in our documentation here, but at least we’ve got a warning about the missing library in the GoPiGo3 - we should make it more clear in one of our next releases.

And finally, you might be interested in going through the documentation of these libraries (GoPiGo3 and DI-Sensors):
https://gopigo3.readthedocs.io
https://di-sensors.readthedocs.io

Please let me know if this did it for you.

Thank you!

Hi Robert,

Thanks for the detailed response. I was following this step by step and ran into an issue when running this line of code.

bash update_sensors.sh --bypass-rfrtools --env-local

“No such file or directory”.

I was able to go into the “home/pi/Dexter/DI_Sensors/Install/update_sensors.sh” and change the config files like you said. Is there something I’m missing?

Thanks!

Just FYI, the line before worked perfectly fine ->

bash update_gopigo3.sh --bypass-rfrtools --env-local
Thanks

Whoops… I missed one line of code. I reran it and it looks like the packages were all listed. However, when I try to import the code and initialize the line follower module it doesn’t work properly. See below for details.

(cv2) pi@dex:~ $ pip list

Package                            Version

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

actionlib                          1.11.13

angles                             1.9.11

backports-abc                      0.5

bondpy                             1.8.3

catkin                             0.7.14

cffi                               1.11.5

cv-bridge                          1.12.8

Dexter-AutoDetection-and-I2C-Mutex 0.0.0

DI-Sensors                         1.0.0

diagnostic-analysis                1.9.3

diagnostic-common-diagnostics      1.9.3

diagnostic-updater                 1.9.3

dynamic-reconfigure                1.5.50

funcsigs                           1.0.2

future                             0.17.1

futures                            3.2.0

gencpp                             0.6.0

geneus                             2.2.6

genlisp                            0.4.16

genmsg                             0.5.11

gennodejs                          2.0.1

genpy                              0.6.7

GoPiGo                             0.0.0

gopigo3                            1.2.0

h5py                               2.8.0

imutils                            0.5.1

interactive-markers                1.11.4

Keras                              2.1.5

laser-geometry                     1.6.4

Line-Follower                      1.0.0

message-filters                    1.12.14

mock                               2.0.0

numpy                              1.15.1

pbr                                4.2.0

picamera                           1.13

Pillow                             5.2.0

pip                                18.0

pluginlib                          1.11.3

protobuf                           3.6.1

pycparser                          2.19

pyserial                           3.4

python-periphery                   1.1.1

python-qt-binding                  0.3.4

pyusb                              1.0.2

PyYAML                             3.13

qt-dotgraph                        0.3.11

qt-gui                             0.3.11

qt-gui-cpp                         0.3.11

qt-gui-py-common                   0.3.11

resource-retriever                 1.12.4

rosbag                             1.12.14

rosboost-cfg                       1.14.4

rosclean                           1.14.4

roscreate                          1.14.4

rosgraph                           1.12.14

roslaunch                          1.12.14

roslib                             1.14.4

roslint                            0.11.0

roslz4                             1.12.14

rosmake                            1.14.4

rosmaster                          1.12.14

rosmsg                             1.12.14

rosnode                            1.12.14

rosparam                           1.12.14

rospy                              1.12.14

rosservice                         1.12.14

rostest                            1.12.14

rostopic                           1.12.14

rosunit                            1.14.4

roswtf                             1.12.14

RPi.GPIO                           0.6.5

rqt-action                         0.4.9

rqt-bag                            0.4.12

rqt-bag-plugins                    0.4.12

rqt-console                        0.4.8

rqt-dep                            0.4.9

rqt-graph                          0.4.9

rqt-gui                            0.5.0

rqt-gui-py                         0.5.0

rqt-image-view                     0.4.13

rqt-launch                         0.4.8

rqt-logger-level                   0.4.8

rqt-moveit                         0.5.7

rqt-msg                            0.4.8

rqt-nav-view                       0.5.7

rqt-plot                           0.4.8

rqt-pose-view                      0.5.8

rqt-publisher                      0.4.8

rqt-py-common                      0.5.0

rqt-py-console                     0.4.8

rqt-reconfigure                    0.4.10

rqt-robot-dashboard                0.5.7

rqt-robot-monitor                  0.5.8

rqt-robot-steering                 0.5.9

rqt-runtime-monitor                0.5.7

rqt-rviz                           0.5.10

rqt-service-caller                 0.4.8

rqt-shell                          0.4.9

rqt-srv                            0.4.8

rqt-tf-tree                        0.5.8

rqt-top                            0.4.8

rqt-topic                          0.4.10

rqt-web                            0.4.8

rviz                               1.12.16

scipy                              1.1.0

sensor-msgs                        1.12.6

setuptools                         40.4.2

singledispatch                     3.4.0.3

six                                1.11.0

smach                              2.0.1

smach-ros                          2.0.1

smbus-cffi                         0.5.1

smclib                             1.8.3

spidev                             3.2

tensorflow                         1.1.0

tf                                 1.11.9

tf-conversions                     1.11.9

tf2-kdl                            0.5.18

tf2-py                             0.5.18

tf2-ros                            0.5.18

topic-tools                        1.12.14

tornado                            5.1.1

Werkzeug                           0.14.1

wheel                              0.31.1

xacro                              1.11.3

You are using pip version 18.0, however version 18.1 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

(cv2) pi@dex:~ $ cd Desktop/CuriousGeorge/

(cv2) pi@dex:~/Desktop/CuriousGeorge $ python line_follower.py

Line Follower not responding

(cv2) pi@dex:~/Desktop/CuriousGeorge $ python

Python 2.7.13 (default, Nov 24 2017, 17:33:09)

[GCC 6.3.0 20170516] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import easygopigo3 as easy

>>> gpg = easy.EasyGoPiGo3()

>>> gpg.init_line_follower()

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "build/bdist.linux-armv7l/egg/easygopigo3.py", line 973, in init_line_follower

File "build/bdist.linux-armv7l/egg/easysensors.py", line 1767, in __init__

ImportError: Line Follower library not found

Ok… last email…

I did some more testing and I was able to import it when I’m not in a folder (i.e. cd ~).

However when I try to import the line_follower module when I’m in a file folder I get an error message that says that the module does not exist. See below.

pi@dex:~/Desktop/CuriousGeorge $ python

Python 2.7.13 (default, Sep 26 2018, 18:42:22)

[GCC 6.3.0 20170516] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import line_follower

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "line_follower.py", line 8, in <module>

import easygopigo3 as easy

ImportError: No module named easygopigo3

>>> cd ~

File "<stdin>", line 1

cd ~

^

SyntaxError: invalid syntax

>>> exit()

pi@dex:~/Desktop/CuriousGeorge $ cd ~

pi@dex:~ $ python

Python 2.7.13 (default, Sep 26 2018, 18:42:22)

[GCC 6.3.0 20170516] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import line_follower

>>> exit()

Please advise!

Thanks,

Will Block
williamfblock@gmail.com

317-385-7945

Hi @williamfblock,

I just tried it again on a fresh Raspbian image (the minimal version) and it worked perfectly for me. Yours doesn’t seem to have the gopigo3 module installed.

Anyway, you mentioned editing the files in Dexter/DI_Sensors/Install/update_sensors.sh/Dexter/GoPiGo3/Install/update_gopigo3.sh. That’s not what you have to do - it’s not the recommended way of installing our robots.

Instead, you have to run the commands I brought up in my previous post in the following manner:

curl -kL dexterindustries.com/update_gopigo3 > update_gopigo3.sh
curl -kL dexterindustries.com/update_sensors > update_sensors.sh

By running these 2, you will end up with 2 files update_gopigo3.sh and update_sensors.sh in the current directory (whatever directory that might be). Then you edit these 2 files and not those in /home/pi/Dexter's subdirectories. After you edit both of them, then you run them. This would be the course of action.

Let me know if this time it worked for you.

Thank you!

Robert,

Thanks for your help, I was able to get it working after running each of the steps again. So I was able to get it to follow a line and stop at a stop sign. See the video for reference!

Really cool stuff. Awesome such a small robot is so powerful.

Thanks!

(Attachment GeorgeDemo.mp4 is missing)https://forum.dexterindustries.com/uploads/short-url/7pgaZzfijJAanTElHmBe1hOqam8.mov

Yeahh!! That’s great news William!

I’m really great to hear you got it up and running and that short video you posted is really cool.

Thank you!