Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 240 → Rev 239

/roboti/istrobot/cholerik/cholerik.c
3,7 → 3,9
 
#include "cholerik.h"
 
#define THRESHOLD 0x8 // rozhodovaci uroven pro okraj areny 0-15 (od 0.25 do 0.75 Vdd)
// Konstanty
#define TRESHOLD 0x90 // rozhodovaci uroven pro okraj areny
//#define DEBUG1 1 // Diagnostika pohonu
 
//motory //Napred vypnout potom zapnout!
#define FR output_low(PIN_B5); output_high(PIN_B4) // Vpred
14,13 → 16,13
#define STOPL output_low(PIN_B6);output_low(PIN_B7)
 
//cidla
#define L 2 // Senzory na okraj areny
#define R 3
#define SIDE_R !input(PIN_A7) // Sensory na soupere
#define SIDE_L !input(PIN_A4)
#define FRONT !input(PIN_A6)
#define BACK !input(PIN_B3)
#define GRAVITY !input(PIN_A1)
// PIN_A3 Prave cidlo na okraj areny (C1OUT)
// PIN_A2 Leve cidlo na okraj areny (C2OUT)
 
#DEFINE SOUND_HI PIN_B1 // komplementarni vystupy pro piezo pipak
#DEFINE SOUND_LO PIN_B2
35,8 → 37,8
unsigned int8 b=0;
unsigned int8 f=0;
unsigned int8 g=0;
int1 arena_l=FALSE;
int1 arena_r=FALSE;
int1 arena_l;
int1 arena_r;
int1 diag=FALSE;
 
#int_TIMER0
51,16 → 53,22
if (((FRONT && stav) || (!FRONT && !stav))) {if (f<255) f++;} else {f=0;};
majak++;
stav = ((majak & 0b1) == 0b1);
 
if (C1OUT) arena_r=TRUE; else arena_r=FALSE;
if (C2OUT) arena_l=TRUE; else arena_l=FALSE;
if (input(PIN_A3)) arena_r=TRUE; else arena_r=FALSE;
if (input(PIN_A2)) arena_l=TRUE; else arena_l=FALSE;
if (stav)
{
// if (read_adc(ADC_READ_ONLY) > TRESHOLD) arena_l=TRUE; else arena_l=FALSE;
// set_adc_channel(R); // prepnuti kanalu ADC, je treba min 10us na ustaleni
// delay_us(10);
// read_adc(ADC_START_ONLY);
set_pwm1_duty(27); // 1:1
}
else
{
// if (read_adc(ADC_READ_ONLY) > TRESHOLD) arena_r=TRUE; else arena_r=FALSE;
// set_adc_channel(L); // prepnuti kanalu ADC, je treba min 10us na ustaleni
// delay_us(10);
// read_adc(ADC_START_ONLY);
set_pwm1_duty(55); // 1:0
};
if (GRAVITY) {if (g<255) g++;} else g=0;
83,11 → 91,47
enable_interrupts(GLOBAL);
}
 
/**** DIAG ********************************************************************/
/******************************************************************************/
inline void diagnostika()
{
unsigned int16 n;
 
#ifdef DEBUG1
while (true) // Diagnostika podvozku
{
for (n=500; n<800; n+=100)
{
beep(n,n); //beep UP
};
Delay_ms(1000);
//zastav vse
STOPL; STOPR;
//pravy pas
FR; Delay_ms(1000); STOPR; Delay_ms(1000);
BR; Delay_ms(1000); STOPR; Delay_ms(1000);
Beep(880,100); Delay_ms(1000);
//levy pas
FL; Delay_ms(1000); STOPL; Delay_ms(1000);
BL; Delay_ms(1000); STOPL; Delay_ms(1000);
Beep(880,100); Delay_ms(1000);
//oba pasy
FL; FR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
BL; BR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
};
#endif
 
//!!!!!!!!!!!!!!!
/*
while(true)
{
set_adc_channel(R); // prepnuti kanalu ADC, je treba min 10us na ustaleni
delay_us(10);
read_adc(ADC_START_ONLY);
delay_ms(1);
delay_ms(read_adc(ADC_READ_ONLY));
beep(1000,200);
}
*/
if (GRAVITY)
{
diag=TRUE;
110,34 → 154,10
Delay_ms(50);
if (b>10) beep(6000,600);
Delay_ms(50);
if((g>100) && arena_l && arena_r) break; // Preklopen na zada a bily papir na obou cidlech na okraj areny
};
 
while (TRUE) // Diagnostika podvozku
{
for (n=500; n<800; n+=100)
{
beep(n,n); //beep UP
};
Delay_ms(1000);
//zastav vse
STOPL; STOPR;
//pravy pas
FR; Delay_ms(1000); STOPR; Delay_ms(1000);
BR; Delay_ms(1000); STOPR; Delay_ms(1000);
Beep(880,100); Delay_ms(1000);
//levy pas
FL; Delay_ms(1000); STOPL; Delay_ms(1000);
BL; Delay_ms(1000); STOPL; Delay_ms(1000);
Beep(880,100); Delay_ms(1000);
//oba pasy
FL; FR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
BL; BR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
};
}
};
}
 
/**** MAIN ********************************************************************/
void main()
{
unsigned int16 n; // for FOR
145,17 → 165,22
STOPL; STOPR; // zastavi motory
 
setup_oscillator(OSC_8MHZ|OSC_INTRC); // CPU clock 8MHz
setup_adc_ports(NO_ANALOGS); // komparatory vypnuty
// setup_adc_ports(sAN2|sAN3|VSS_VDD); // prevodniky na cidla na okraj areny
// setup_adc(ADC_CLOCK_INTERNAL);
//!!!!!!!!!!!!!!!!!!
setup_adc_ports(NO_ANALOGS); // prevodniky na cidla na okraj areny
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4); // Casovac pro SW PWM a cteni cidel
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4); // Casovac pro SW PWM a cteni cidel
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,54,1); // Casovac pro PWM pro IR sensory cca 36kHz
setup_ccp1(CCP_PWM); // HW PWM ON
set_pwm1_duty(27); // 1:1
setup_comparator(A3_VR_A2_VR); // inicializace komparatoru
setup_vref(VREF_HIGH|THRESHOLD); // 16 kroku od 0.25 do 0.75 Vdd
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
set_adc_channel(R);
 
Beep(1000,200); //double beep
Delay_ms(50);
Beep(1000,200);
163,7 → 188,7
 
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
 
/*---------------------------------------------------------------------------*/
for (n=1;n<=5;n++) // 5s do zacatku souboje
{
Delay_ms(720);
170,7 → 195,6
Beep(1000,200);
}
 
/*----- Main Loop ------------------------------------------------------------*/
while(true) // hlavni smycka
{
LOOP: