Resumen
Necesitas dos hubs y dos de cada tipo de rueda. Utilizo juntas tóricas de 30 mm x 40 mm x 5 mm disponibles en Amazon. Necesitas 4 tornillos M3 x 25 mm para sujetar los motores y 2 tornillos de 8-32 3/4" para un juego de ruedas. Necesitas dos motores disponibles de Sparkfun (2 motores de hobby por $5), un controlador de motor con conectores de Sparkfun por $5, un pa
https://www.youtube.com/watch?v=ioGz1LwgC6o
Parece que algunas de las inclusiones en el código confunden al procesador de HTML.
/*
- Archivo: R06Main.c
- Autor: hmikelson.
- Creado el 4 de septiembre de 2018, a las 6:11 PM.
*/
Incluir.
Incluir.
Incluir.
Pragma config MCLRE=OFF, CP=OFF, WDTE=OFF, FOSC=INTOSC
Define _XTAL_FREQ 16000000
char no firmado sPORTA, sPORTC, pwmax=31;
void init()
{
//Configurar puerto GPIO
TRISA = 0b110000000; //Establece toda la salida.
TRISC = 0b110001000; // Configura el pin 3 para entrada.
OSCCONbits.IRCF = 0b1111;
OSCCONbits.SCS = 0b00;
//OPTION_REG = 0b01111111; //Habilitar globalmente los pullups débiles.
//WPUC = 0b00001000; //Habilita los pullups débiles con un 1.
// Configurar la entrada analógica.
ANSELCbits.ANSC3 = 1;
ADCON0 = 0b00011101; // Canal (CHS4: 0 bits 6-2), ADON bit 1 habilita Analógico.
ADCON1bits.ADCS = 0b111; // selección de reloj para oscilador dedicado.
ADCON1bits.ADNREF = 0; //referencia negativa
ADCON1bits.ADPREF = 0; //configuración + voltaje con vdd
ADCON1bits.ADFM = 1; //formato justificado a la izquierda
ADRESH = 0x00; // Inicia el registro AD.
ADRESL = 0x00; // No creo que esto sea necesario.
}
void vdelay(int n)
{
int i;
para (i=0;i<=n;i++)
{
__delay_us(100);
}
}
int read_v()
// Leer el voltaje de la entrada.
{
int val,v1,v2;
__delay_ms(1);
ADCON0bits.GO_nDONE = 1;
mientras (ADCON0bits.GO_nDONE == 1);
v1 = ADRESH;
v2 = ADRESL;
val = (v1<<8) + v2;
devuelve val;
}
void RobotFd(int tiempo, unsigned char velocidad)
{
int i, j;
para (i=0;i<tiempo;i++)
{
para (j=0;j<pwmax;j++)
{
si (j<velocidad)
{
PORTA = 0b00111110; //
PORTC = 0b00010110; // Habilitar en el pin 4
vdelay(pwmax/speed);
}
de lo contrario
{
PORTA = 0b00000110; // Creo que hay una salida de reloj en el pin 4, que no sé cómo desactivar.
PORTC = 0b00010010; // Habilitar en el pin 4
vdelay(pwmax/speed);
}
}
void RobotBk(int tiempo, caracter sin signo de velocidad)
{
int i, j;
para (i=0;i<tiempo;i++)
{
para (j=0;j<pwmax;j++)
{
si (j<velocidad)
{
PORTA = 0b00111101;
PORTC = 0b00010101;
vdelay(pwmax/speed);
}
de lo contrario
{
PORTA = 0b00000101;
PORTC = 0b00010001;
vdelay(pwmax/speed);
}
}
void RobotRt(int tiempo, unsigned char velocidad)
{
int i, j;
para (i=0;i<tiempo;i++)
{
para (j=0;j<pwmax;j++)
{
si (j<velocidad)
{
PORTA = 0b00111110;
PORTC = 0b00010101;
vdelay(pwmax/speed);
}
de lo contrario
{
PORTA = 0b00000110;
PORTC = 0b00001001;
vdelay(pwmax/speed);
}
}
void RobotLt(int tiempo, caracter sin firmar velocidad)
{
int i, j;
para (i=0;i<tiempo;i++)
{
para (j=0;j<pwmax;j++)
{
si (j<velocidad)
{
PORTA = 0b00111101;
PORTC = 0b00110110;
vdelay(pwmax/speed);
}
de lo contrario
{
PORTA = 0b00000101;
PORTC = 0b00001010;
vdelay(pwmax/speed);
}
}
void RobotSt(int tiempo)
{
int i;
para (i=0;i<tiempo;i++)
{
PORTA = 0b00000100;
PORTC = 0b00001100;
__delay_ms(10);
}
}
void main()
{
int rmode, rtime, volts,mt=31;
Un carácter sin firmar rspeed, nactions=0;
init();
RobotFd(100,pwmax/2);
RobotSt(1);
RobotRt(100,pwmax/2);
RobotSt(1);
RobotBk(100,pwmax/2);
RobotSt(1);
RobotLt(100,pwmax/2);
RobotSt(1);
mientras(1)
{
si (nactions > 0)
{
rmode=(rand() & 7) + 1;
nactions=nactions-1;
}
de lo contrario
{
rmode = 0;
}
rtime = (rand() & 7)+1;
rspeed = rand() & pwmax;
switch (rmode)
{
Caso 1:
RobotFd(rtime <en> RobotFdmt,rspeed);
RobotSt(1);
Pausa;
caso 2:
RobotBk (rtimemt,rspeed);
RobotSt(1);
Pausa;
Caso 3:
RobotRt (rtime <)mt,rspeed);
RobotSt(1);
Pausa;
Caso 4:
RobotLt (tiempo restante)mt,rspeed);
RobotSt(1);
Pausa;
Caso 0:
RobotSt(1);
voltios = read_v();
si (volts>50)
{
naciones = 10;
//blink(volts);
}
Pausa;
Por defecto:
RobotSt(10);
Pausa;
}
}
}
태그
모델 소스
