How to increase 3pi speed

The place to discuss the Pololu 3pi robot and share your code.

Re: How to increase 3pi speed

Postby Ben on Thu Jun 03, 2010 11:02 am

It looks like we never updated the QTR sensor library for the Orangutan SVP and Orangutan X2, which is why you're having problems with the IO_Cx macros from OrangutanDigital (since OrangutanDigital has been updated for the SVP). Unfortunately, you won't be able to use the IO_Ax pins with the QTR sensor library until we update it.

Your problem with PB4 is that it is the slave-select line of the SPI module, so there are restrictions on its use when you are communicating with the auxiliary MCU (as happens when you try to read the encoders). The SPI module will only work in master mode if PB4 is an input that reads high (the Pololu AVR library configures it as a input with the internal pull-up enabled once the SPI module is initialized) or if it is an output. You should be able to alternate reading the encoders and QTR sensors by manually configuring PB4 as an output when you want to use SPI and as an input with internal pull-up disabled when you want to read the sensors.

- Ben
User avatar
Ben
Site Admin
 
Posts: 1362
Joined: Mon Aug 28, 2006 1:05 pm
Location: Las Vegas, NV

Re: How to increase 3pi speed

Postby jlake on Thu Jun 03, 2010 3:26 pm

Hi Ben,

Thanks for the prompt reply. Anyhow, with regards to the line sensing and encoder - I guess I might find some means to compute the speed of the robot. Does this mean that I cannot used the USB capability of SVP if I will used the line sensor?
jlake
 
Posts: 10
Joined: Mon May 17, 2010 11:15 am

Re: How to increase 3pi speed

Postby Ben on Thu Jun 03, 2010 3:41 pm

Pin PB4 will affect all communication between the user MCU (ATmega1284) and the auxiliary MCU, so if you want to use PB4 for the line sensor, you will need to manually configure the state of PB4 as is appropriate for whatever action you are trying to perform (i.e. set it as an output or pulled-up input when using SPI). If you set it as a pulled-up input, you should delay for a few milliseconds to let the voltage rise and stabilize before you try using SPI. You could also just use seven of the eight reflectance sensors and leave pin PB4 free, or you could to add support for port A pins to the QTR library source code (if you don't want to wait for us to do it).

- Ben
User avatar
Ben
Site Admin
 
Posts: 1362
Joined: Mon Aug 28, 2006 1:05 pm
Location: Las Vegas, NV

how to use QTR RC sensors on SVP

Postby DavidEGrayson on Fri Jun 04, 2010 2:38 pm

I did some experiments. It turns out that PB4 can not be used as a digital input while the SPI module is enabled (PINB bit 4 is always 0). We already knew that using PB4 as a digital input could cause the SPI module to fail (that's why the SVP user's guide says that we recommend making PB4 an output), but we didn't know that SPI causes digital input to fail. If you really want to use PB4 as an input, you can temporarily disable the SPI module (by clearing the SPE bit in SPCR).

So jlake, if you want to get all 8 of your QTR sensors working right now, I suggest adding code around your QTR-reading code like this:

Code: Select all
unsigned char saved_spcr = SPCR;   // Save the state of the SPI module
SPCR &= ~(1<<SPE);                 // Disable SPI module so PB4 can be used as input
qtr_read(values, QTR_EMITTERS_ON); // change this to whatever type of QTR reading you want to do
set_digital_output(IO_B4, LOW);    // Make PB4 an output so it doesn't interfere with SPI.
SPCR = saved_spcr;                 // Restore the state of the SPI module.


This code worked for me, allowing me to read analog channel A from the auxiliary processor via SPI and also read a QTR-RC sensor on PB4 in the same program. This code also works if you drive PB4 high instead of low, but that would cause increased power consumption.

Also, later today we should have a new version of the Pololu AVR Library out that allows you to use pins A0-A7 for your sensors, so you won't have to deal with the quirks of PB4. When we release it, we'll make an announcement in the announcements forum.

--David
DavidEGrayson
Site Admin
 
Posts: 311
Joined: Thu Apr 03, 2008 12:30 pm
Location: Las Vegas, Nevada

Re: How to increase 3pi speed

Postby DavidEGrayson on Fri Jun 04, 2010 6:45 pm

I didn't manage to officially release the new AVR library and update the documentation today, but I have made the new version available for you to download at this link:

http://www.pololu.com/file/0J380/libpol ... 100604.zip

That should let you put QTR sensors on port A using the IO_A0...IO_A7 macros, so there is no need to try to get them working on PB4. Enjoy!

-David
DavidEGrayson
Site Admin
 
Posts: 311
Joined: Thu Apr 03, 2008 12:30 pm
Location: Las Vegas, Nevada

Re: How to increase 3pi speed

Postby jlake on Mon Jun 07, 2010 8:24 am

Hi david and Ben,

Thanks for the reply. Anyways, I am using QTR-RC sensors - can I still used the IO_A0 on this sensor or do I need to but the other line sensor you have?

Thanks again,
jlake
 
Posts: 10
Joined: Mon May 17, 2010 11:15 am

Re: How to increase 3pi speed

Postby jlake on Mon Jun 07, 2010 8:48 am

DavidEGrayson wrote:I didn't manage to officially release the new AVR library and update the documentation today, but I have made the new version available for you to download at this link:

http://www.pololu.com/file/0J380/libpol ... 100604.zip

That should let you put QTR sensors on port A using the IO_A0...IO_A7 macros, so there is no need to try to get them working on PB4. Enjoy!

-David


Hi David,

If so that I can used the QTR-RC in the analog pin - then I might have some problems - since I will be using at least 4 analog pins for my other sensors. What I have done so far were these:

I managed to used only 5 line sensors:
unsigned char qtr_rc_pins[] = {11, 14, 15, 0, 1}; // I tried to get rid of PB4 as I need the serial port at UART1
Used UART1 as my wireless tx/rx to my PC
serial_set_baud_rate(UART1, 9600); // using UART1
serial_receive_ring(UART1, receive_buffer, sizeof(receive_buffer));

I tested the serial - works perfectly. But when I tried to run the robot - it's kind of weird - one motor is not running the way it used to be - and I guess it still have problems even when I tried not to used the PB4.

what did I miss?
jlake
 
Posts: 10
Joined: Mon May 17, 2010 11:15 am

Re: How to increase 3pi speed

Postby DavidEGrayson on Mon Jun 07, 2010 9:58 am

jlake wrote:If so that I can used the QTR-RC in the analog pin - then I might have some problems - since I will be using at least 4 analog pins for my other sensors.


I'm not saying that you should put all of your QTR-RC sensors on port A (the analog port). You can have some of them on port A and some of them other ports, according to what you need.

jlake wrote:unsigned char qtr_rc_pins[] = {11, 14, 15, 0, 1}; // I tried to get rid of PB4 as I need the serial port at UART1


Pin numbers 14-20 have a different definition on the SVP (and X2) than they do on our other devices, so to make your code clear you should use the IO_* macros. For example: { IO_B3, IO_C0, IO_C1, IO_D0, IO_D1 }. Also have you downloaded and installed the new version of the Pololu AVR Library I linked to in my last post? You should do that so that the PololuQTRSensors section of the library interprets those new pin numbers correctly. After you do that, you should be able to use all 8 of your QTR sensors if you want to and you have enough free pins.

Also, why do you think that PB4 is related to UART1? As far as I know, PB4 is related to SPI, but not UART1. Do we have any documentation that mistakenly says that PB4 is related to UART1? If so, you should tell us where that documentation is so we can fix it.

jlake wrote:I tested the serial - works perfectly.


Great!

jlake wrote:one motor is not running the way it used to be


What are the differences between the program that previously worked and the program that doesn't work now? Can you load the previously-working program on the SVP and see if it sill works? Which version of the Pololu AVR Library are you using? Can you simplify your program and post the simplest possible program that doesn't work, and describe the expected behavior and actual behavior?

-David
DavidEGrayson
Site Admin
 
Posts: 311
Joined: Thu Apr 03, 2008 12:30 pm
Location: Las Vegas, Nevada

Re: How to increase 3pi speed

Postby jlake on Mon Jun 07, 2010 10:32 am

Hi Dave,

The only difference for the working code was that I used PB4 on it and now I used:

PB3, PC0, PC1, PD0, PD1

I checked each of the sensor on this new pin connections and it reported correct readings. But when I started to run the robot - it veers to the left and somehow lost it orientation.

So I put the PB4 back and get commented my serial initialization and it works perfectly.

Previously used ports was: PB3, PB4, PC0, PC1 PD0.
jlake
 
Posts: 10
Joined: Mon May 17, 2010 11:15 am

Re: How to increase 3pi speed

Postby jlake on Mon Jun 07, 2010 11:35 am

Hi Dave and Ben,

I got it to work after I put the new libraries you send.
thanks a lot.
jlake
 
Posts: 10
Joined: Mon May 17, 2010 11:15 am

Previous

Return to 3pi Robot

Who is online

Users browsing this forum: No registered users and 2 guests