Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum

Infrarotsteuerung Kategorie: Pro-Bot128 (von PepeV - 16.10.2010 10:24)
Ich nutze:
Pro-Bot128
Hi all,

For only 3 Euros I bought a simple IR remote control in a department store. With it I made a remote
control for the robot and a wealth of possibilities opened for me. The IR sensor of the robot is so
sensitive that the robot can be controlled over a distance of at least 7 meters from any (!) direction.
I think this is a possibility every Pro-bot owner should have. Though the solution is quite simple, it cost
me a lot of time to realize it and therefore I want to share what I made.

The RC transmitter I bought is programmable. With help of the manual and a lot of trial and error I
found a setting that uses the required RC-5 Philips protocol. The transmitter has 6 buttons and a switch
for TV or Satellite control. So 12 commands should be possible. In practice, there were only 11.

There is an example of an IR receiver in the collection C-Control Pro Demos. However this approach is
not suitable for the robot because it takes to much processor time. Every time RC5_Read() is called in
the loop, 130 ms is used, even when there is no IR signal. It is much more efficient to call RC5_Read()
only after an interrupt that is triggered by the IR-sensor at the beginning of a signal. I used the following
program.

#define TSOP 26
 
byte NewCommand;
word KeyCode, RC_Code, OldRC_Code, DeviceCode;
 
void main(void)
{
    RC_Init();
    NewCommand = false;
    RC_Code = 0;
 
    while (true)
    {
        if (RC_Code!=0)
        {
            KeyCode = RC_Code & 0b000000111111; // Extract bits 1 t/m 6
            DeviceCode = (RC_Code & 0b011111000000) >> 6;
                  // Extract bits 7 t/m 11 and shift right by 6 positions
 
            // The toggle bit (bit 12) is inverted when the same key is pushed  
            // again, not if the key is held and automatic repetition occurs.
            // Thus it is possible to distinguish between those two kinds of
            // repetition.
 
            if (OldRC_Code != RC_Code)
            {
                NewCommand = true;
                OldRC_Code = RC_Code;
            }
            else NewCommand = false;

            RC_Code=0;
            Process_RC_Code(KeyCode, DeviceCode, NewCommand);
        }
    }
}
 
void RC_Init(void)
{
    RC5_Init(TSOP);
    Ext_IntEnable(2,2); // TSOP is active low so falling edge trigger
    Irq_SetVect(INT_2, TSOP_ISR); // TSOP is connected to port 26 = interrupt 2
}
 
void TSOP_ISR(void)
{
    int irqcnt;
    RC_Code = RC5_Read();
    irqcnt = Irq_GetCount(INT_2);          //Interrupt Request Counter = 0
}
 
void Process_RC_Code(byte aKeyCode, byte aDeviceCode, byte aNewCommand)
{
    if (aDeviceCode == 0) // TV
    {
        switch (aKeyCode)
        {
            case 12: // Start/Stop
                if (aNewCommand)
                {
                    // Place your commands here
                }
                else
                {
                    // Place your commands here
                }
            break;
            case 32: // Prog+
                if (aNewCommand)
                {
                    // Place your commands here
                }
                else
                {
                    // Place your commands here
                }
            break;
            // Etcetera for other keycodes like 17 (Vol-), 16 (Vol+), 33 (Prog-), 13 (Mute)
        }
    }
    else
    {
        if (aDeviceCode == 8) // SAT
        {
            switch (aKeyCode)
            {
                case 12: // Start/Stop

                    if (aNewCommand)
                    {
                        // Place your commands here
                    }
                    else
                    {
                        // Place your commands here
                    }
                break;
                // Etcetera for other keycodes
            }
        }
    }
}


Regards,
Pepe


    Antwort schreiben


Antworten:

Re: Infrarotsteuerung (von ulrich korth - 18.10.2010 9:36)
    Re: Infrarotsteuerung (von Ondra - 16.01.2011 19:02)
        Re: Infrarotsteuerung (von PepeV - 18.01.2011 16:05)