Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Help with Hybrid code (http://www.chiefdelphi.com/forums/showthread.php?t=64083)

ShotgunNinja 14-02-2008 16:22

Help with Hybrid code
 
I have been having trouble with my Hybrid mode setup. I'm not sure what exactly is the problem, but I have been led to believe it is my sometimes flawed programming. :o (See my other posts if you don't believe me). I am using the provided IR board, and with a regular IR remote setup, for a VCR remote. The outputs are (supposedly) wired into Digital In/Out ports #1-4, and the IR board is receiving power.

Here is my code (it's a bit un-simplified, so propagators of KISS please don't complain too much)

Code:

/* Some globals: */
unsigned char offsensor1;
unsigned char offsensor2;
unsigned char offsensor3;
unsigned char offsensor4;

/* Initialize */
void Initialize(void)
{
  InitIRSensor();
  /* ... */
}

/* InitIRSensor */
void InitIRSensor(void)
{
  offsensor1 = GetDigitalInput(1);
  offsensor2 = GetDigitalInput(2);
  offsensor3 = GetDigitalInput(3);
  offsensor4 = GetDigitalInput(4);
}

/* Autonomous */
void Autonomous(void)
{
  unsigned char irsensor1;
  unsigned char irsensor2;
  unsigned char irsensor3;
  unsigned char irsensor4;
  int action = 0;
 
  while( IsAutonomous() )
  {
      irsensor1 = GetSensorInput(1);
      irsensor2 = GetSensorInput(2);
      irsensor3 = GetSensorInput(3);
      irsensor4 = GetSensorInput(4);
      if ((irsensor1 + irsensor2 + irsensor3 + irsensor4) >= 2)
      {
        action = 0;
      }
      else if (irsensor1)
      {
        action = 1;
      }
      else if (irsensor2)
      {
        action = 2;
      }
      else if (irsensor3)
      {
        action = 3;
      }
      else if (irsensor4)
      {
        action = 4;
      }
      else
      {
        action = 0;
      }
      HybridAction(action);
  }
}

/* GetSensorInput */
unsigned char GetSensorInput(int sensorPort)
{
  unsigned char value;
  switch(sensorPort)
  {
      case 1:
      {
        value = offsignal1;
        break;
      }
      case 2:
      {
        value = offsignal2;
        break;
      }
      case 3:
      {
        value = offsignal3;
        break;
      }
      case 4:
      {
        value = offsignal4;
        break;
      }
  }
  return(GetDigitalInput(sensorPort) == value);
}


Kingofl337 15-02-2008 13:42

Re: Help with Hybrid code
 
Check the on-line window and see if your sensor is working. You should see ports 1-4 reading 0. When the button is pressed on your remote, the indicator should swap to 1 while the LED is on.


All times are GMT -5. The time now is 00:59.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi