Hi, I am trying to implement a feature to be able to control my GoPiGo car with PS4 Controller. I have installed PyPS4, and ds4drv and successfully connected my PS4 controller via bluetooth to my Rpi 4 and it is connected fine and all the buttons are recognised when I press them. However, I am unable to control my motors and run the car itself. Any help would be very much appreciated!
We don’t have quite enough details to help here.
Can you control the robot otherwise? Do you have a good battery (the robot won’t move if it’s not getting powered properly)
This is my code for my Controller.py. At the moment, it is only able to identify what buttons I have pressed. The motors do not move at all. I did test the motors to see if they were working ok with a test motor file I made and they move perfectly fine. But unfortunately they do not move at all when I run the Controller.py code I don’t know whether it’s to do with the functions I have written.
You have an error in the file called Motor.py which you haven’t shared.
Sorry, I have now attached my Motor.py. It does come up with a TypeError but the motors are still working. Just unsure on how to make them work when using the PS4 controller for Controller.py
There should be no ‘3’ in the stop() command. It is just egpg.stop()
Oh okay thanks I have changed this now! I’m still unsure why my Controller.py code isn’t running my motors. My battery life is fine I have just replaced it with 8 batteries in the battery pack.
Can you share a photo of the robot, please?
Also can you add print statements in Controller.py, just before each call to egpg. For example, add one just above line 15.
print("Going forward")
egpg.forward()
Also, try it from the command line, outside of Thonny. Open up a terminal, navigate to the proper folder, and run it from there.
python3 Controller.py
That might give us more info.
Here is an image of my robot.
I have added those print statements now. Unfortunately when I run the script both in Thorny and in terminal through SSH it is coming up with a Fatal Error to state the GoPiGo3 and SPI isn’t detected and address 8 is not detected. I have come across this issue before in the past and was recommended to flash the firmware after doing this it resulted in my car being completely non functional as I am using rpi4. It would state ‘firmware version needs to be 3.0.x’ or something along those lines.
@cleoqc Update: After Rebooting the raspberry pi it no longer comes up with that fatal error which is good but the only thing that is being printed out is the buttons I am pressing and not the print statements which is a bit strange I’m not sure why that’s happening.
I’ve also tried running it in terminal again through SSH but it is also doing the same printing just the buttons and not the print statements.
-
The operating system I am using is Raspberry Pi OS (Legacy) and I have downloaded the GoPiGo3 libraries by using these commands: curl -kL dexterindustries.com/update_gopigo3 | bash
curl -kL dexterindustries.com/update_sensors | bash -
I only have a pi-4. i have tried flashing the firmware on the pi4 probably about a month ago and then the motors code that I wrote did not work at all and none of the examples in the Dexter/Software/Python/Examples worked so I had to flash the os again and re-set the whole of the Raspberry Pi.
It’s really strange because the motors do work but when running my code for the PlayStation Controller the buttons are recognised but the motors do not run even though I am using egpg.forward() after pressing the up arrow. I was wondering if it may be to do with the code itself rather than a hardware issue?
The motors do however, work when I run Motor.py example from dexter and my motor code.
I know that now! I did it a while ago and it resulted in my robots being completely non-functional and firmware version errors!
No I don’t have to keep holding the power button it does boot up ok.
Ok I will try and see if my supervisor has one spare, it’s for my final year bachelors project you see. I did mention this issue to him but a previous student has implemented their pi4 with a ps4 controller and gopigo3 so it is possible but just unsure on how to get it working.
-
I will check the hardware is correct but everything else seems to be working fine apart from the Controller code.
-
Okay I have tried setting the speed of the egpg by putting egpg.set_speed(100) But it still doesn’t seem to run the motors.
I will probably need to write something like that for my motor module code. I have looked at the PyPS4 library that I am using in my Controller.py code and was wondering if that is definitely compatible with gopigo3? Or if there is another library I could maybe use instead? It also states that default mapping for buttons can be off so that could be an issue? I’ve just looked on git and found the library and functions for PyPS4. Maybe I need to intergrate ‘egpg.forward()’ into the list of actions? I am confusing myself with all of this to be honest
I did also try running the examples from Dexter/Software/Python/Examples Basic_Robot_Control but this did not work either, maybe because I’m using python3 rather than Python2 and it is in the GopiGo library rather than GoPiGo3?
I will have a look into GoPiGo OS would it make a difference functionality wise? I am using Raspberry Pi OS (Legacy) and that seems to be ok! I previously used Raspian for Robots but I found that it was incompatible with the Raspberry Pi 4.
I’ve just found a spare micro sd card so I will try flashing GoPiGo OS on there and running the examples. Thanks!
Yes I am using a virtual environment to run the code. But I have also tried running scripts from terminal and that didn’t work well either.