Getting wheel turns

Hello, I am currently undergoing a project whereby I hope to have a robot navigating and mapping a room. I have got the GoPiGo and have managed to set it up and get it running but I have one question in regards to the enc_tgt function. Is it possible to return the number of times the wheel has turned since a certain point, so as to get the distance that the robot has travelled? Or is it only possible to set the number of times it will turn from a certain point?

You can use the enc_read() function to read the encoder value from the GoPiGo. Here is an example: https://github.com/DexterInd/GoPiGo/blob/master/Software/Python/enc_val_read.py and what you can do is read it at the start so that you know the initial encoder positions and then read it something like once a second just to check how much it has changed. Something like in this example: https://github.com/DexterInd/GoPiGo/blob/master/Software/Python/other_scripts/encoder_tgt_complete_test.py#L63. You can use these counts to find out how much has the wheel rotated. 18 counts mean 1 rotation and each count comes out to 1-1.1cm of travel depending on the radius of your wheel.

-Karan

Thank you for the reply Karan, I will have a look at those examples you have provide.

I also have another question that you may be able to help with. My GoPiGo is veering to the left when the fwd() command is called. I have followed steps to add the trim value to the wheels but no value entered resolves the problem. I have trim currently set to 100 and it is still turning to the left. Is there any way to fix this?

Also is there a way to quickly stop the GoPiGo when you exit a script? Rather than having to input the stop() command into the file

Just to update, I have resolved the issue with the wheels. It seems that running the wheels at a slower speed stops this issue

great to hear that the GoPiGO is working well for you. Yo make it stop on exit using atexit . You can check an example here https://github.com/DexterInd/GoPiGo/blob/master/Software/Python/basic_test_all.py#L25-L26.

-Karan

I have another question in regards to connecting a HC-SR04 sensor to the A1 port. I have seen the forum post about this but I am still unable to get any measurements from us_dist(15) and it is simply printing 0’s. On the forum post you state that the connection is ordered GND,VCC,A1,A1 but this doesn’t match up with the order on the HC-SR04. I currently just have a grove cable attached to A1 and then to the Ultrasonic sensor, and have tried multiple sensor that I know work.

These are the cables I am using : http://www.unmannedtechshop.co.uk/grove-universal-4-pin-buckled-20cm-cable-5-pcs-pack/, with an arduino HC-SR04 sensor.

Hey diggerdedoo,
The HC-SR04 come in different pinouts and configuration. The one we use is this http://www.dexterindustries.com/shop/ultrasonic-sensor/ which comes with only one pin and is a Seeed module. We had tried out different modules when choosing the ultrasonic sensors and found the seeed on the most reliable and with repeatable results. The cable look good but I am not really sure about what kind of sensor you have and how to get it working with the GoPiGo. The best way would be to get an official ultrasonic sensor.

-Karan

Hey Karan,

Thank you for your help, its much appreciated. I will have a look at purchasing one of those sensors if I can not manage to get mine working. I should have said the sensor is: http://www.gearbest.com/development-boards/pp_58067.html?currency=GBP&gclid=CIyuloiQncwCFfMV0wodP5AMSw.

Hello Again,

Just to update, The HC-SR04 sensor works and is now returning distances. It was a matter of using some more female to male cables to rearrange the order the pins are connected to the grove cable.

Thank you again for your help Karan.

Hey diggerdedoo,
Great to hear that the sensor works for you, can you post some pictures and information on how you connected the sensor. It might be useful for other people who try using a similar sensor in the future.

-Karan

Of course, I’ll post some picture when I can, until then this is what I did.

As you have stated previously the A1 port’s pins are ordered from left to right, GND, VCC, A1, A1. As HC-SR04 sensor pins don’t align to this when connected using a grove cable it is simply a matter of using some cables to ensure that they do.

In my case, the HC-SR04 pins align as VCC, Trig, Echo, GND and by matching the order to that of the A1 port I was able to get readings using us_dist(15)