Magazine Mar2010 vol.4 [2 wheeled balancing robot]

Anything related to the ROBOT. Head to Toe Magazine.

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

Postby waiweng83 » Wed May 23, 2012 5:46 pm

choyhong88 wrote:i have some doubt in the provided source code, filename adc.c

why all the adc result is put in (signed int)ADCBUF0? will each of the result overwrite the previous result, then in the end we will only obtain the adc result for si_adc_right_motor_2 and the rest of result is gone? :?


Code: Select all
void adc_start_conversion(void)
{
        // Turn off PWM and let the back EMF become stable.
        // While waiting, we will sample the other channels first.
        OC1CONbits.OCM = 0;
        OC2CONbits.OCM = 0;
       
       
        // Select AN0 (Vin).
        ADCHSbits.CH0SA = 0;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        sui_adc_supply = (signed int)ADCBUF0;
       
       
       
        // Select AN1 (Acc - X).
        ADCHSbits.CH0SA = 1;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        sui_adc_acc_x = (signed int)ADCBUF0;
       
       
       
        // Select AN3 (Gyro).
        ADCHSbits.CH0SA = 3;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        sui_adc_gyro = (signed int)ADCBUF0;
       
       
       
        // Select AN4 (Left Motor Voltage - 1).
        ADCHSbits.CH0SA = 4;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        si_adc_left_motor_1 = (signed int)ADCBUF0;
       
       
       
        // Select AN5 (Left Motor Voltage - 2).
        ADCHSbits.CH0SA = 5;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        si_adc_left_motor_2 = (signed int)ADCBUF0;
       
       
       
        // Select AN6(Right Motor Voltage - 1).
        ADCHSbits.CH0SA = 6;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        si_adc_right_motor_1 = (signed int)ADCBUF0;
       
       
       
        // Select AN7 (Right Motor Voltage - 2).
        ADCHSbits.CH0SA = 7;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
       
        // Delay 100uS.
        __delay32(_XTAL_FREQ/40000);
       
        // Stop sampling and start conversion.
        ADCON1bits.SAMP = 0;
       
        // Wait for conversion to finish.
        while (ADCON1bits.DONE == 0);
       
        // Save the value.
        si_adc_right_motor_2 = (signed int)ADCBUF0;
       
       
       
        // Turn on PWM.
        OC1CONbits.OCM = 0b110;
        OC2CONbits.OCM = 0b110;
       
        // At last, before we exit, we start sampling AN0 (Vin) as it has a low output impedance.
        ADCHSbits.CH0SA = 0;
       
        // Start sampling.
        ADCON1bits.SAMP = 1;
}       


should we save the adc value in this way

sui_adc_supply = (signed int)ADCBUF0;
sui_adc_acc_x = (signed int)ADCBUF1;
sui_adc_gyro = (signed int)ADCBUF2;
si_adc_left_motor_1 = (signed int)ADCBUF3;
si_adc_left_motor_2 = (signed int)ADCBUF4;
si_adc_right_motor_1 = (signed int)ADCBUF5;
si_adc_right_motor_2 = (signed int)ADCBUF6;



Yup. The value in ADCBUF0 will be overwritten when the next conversion completed. Thus we need to save it before start the next conversion.

choyhong88 wrote:And another doubt, the circuit diagram show that using 2 out of the 3 axis in accelerometer but in the source code only 1 axis is need. So, acually 1axis + 1 gyro rate are enough for balancing ..


For 2 wheel balancing robot, 1 accelerometer is already enough.
With the power of dream, nothing is impossible...
User avatar
waiweng83
Moderator
 
Posts: 155
Joined: Wed Apr 15, 2009 2:17 pm

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

Postby ycwong » Sat May 25, 2013 7:10 pm

Hi All,

Currently I face the problem on the ADC value and Sensitivity for gyro, which define in firmware system.h.

The value i get is
// ADC value when the acceleration is -1G.
ACC MIN X is 1267.

// ADC value when the acceleration is 0G.
ACC MID X is 1577.

// ADC value when the acceleration is 1G.
ACC MAX X is 1875.

I notice that, these value is different from what is define in firmware system.h.
Can anybody please provide me the detail calculation of getting these ACC MIN, ACC MID, ACC MAX, GYRO_ZERO and GYRO_SENSITIVITY.

Thanks in advanve.
ycwong
Freshie
 
Posts: 4
Joined: Thu Oct 20, 2011 1:29 pm

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

Postby waiweng83 » Tue May 28, 2013 11:24 am

ycwong wrote:Hi All,

Currently I face the problem on the ADC value and Sensitivity for gyro, which define in firmware system.h.

The value i get is
// ADC value when the acceleration is -1G.
ACC MIN X is 1267.

// ADC value when the acceleration is 0G.
ACC MID X is 1577.

// ADC value when the acceleration is 1G.
ACC MAX X is 1875.

I notice that, these value is different from what is define in firmware system.h.
Can anybody please provide me the detail calculation of getting these ACC MIN, ACC MID, ACC MAX, GYRO_ZERO and GYRO_SENSITIVITY.

Thanks in advanve.



Every gyro and accelerometer will have its value slightly different. Just change the value in the system.h accordingly to what you get.
With the power of dream, nothing is impossible...
User avatar
waiweng83
Moderator
 
Posts: 155
Joined: Wed Apr 15, 2009 2:17 pm

Re: Magazine Mar2010 vol.4 [2 wheeled balancing robot]

Postby ycwong » Tue Jun 25, 2013 8:19 am

Hi All,

Noted and thanks.

I face another problem is the mounting of the gyro and accelerometer. Can I have the clear image of the two wheel balancing robot that build by cytron because the picture published in the volume 4 RH2T When I zoom in, the image is blur. I can't see
the component (gyro and accelerometer) mouting clearing. If can , please provide me the photo of the two wheel balancing robot. This photo should be as a reference for me.


Thanks.
ycwong
Freshie
 
Posts: 4
Joined: Thu Oct 20, 2011 1:29 pm

Previous

Return to ROBOT. Head to Toe Magazine

Who is online

Users browsing this forum: No registered users and 2 guests