ROBOTC.net forums
http://www.robotc.net/forums/

Delay with HTIRL
http://www.robotc.net/forums/viewtopic.php?f=41&t=2497
Page 1 of 1

Author:  DiMastero [ Mon Jul 19, 2010 1:25 pm ]
Post subject:  Delay with HTIRL

Hi there,

when I use my HTIRL in a very simple program (see below) there is a pretty big delay between me pressing the touch sensor, and the motors moving (about one sec)...

Code:
#pragma config(Sensor, S1,     HTIRL,               sensorLowSpeed)
#pragma config(Sensor, S4,     TouchSensor,               sensorTouch)

#include "drivers/HTIRL-driver.h"

task main()
{
  int MotorA_cmd = 9;
  int MotorB_cmd = 7;

  while (true)
  {
    if (SensorValue (TouchSensor) == 1)
    {
      PFcomboPwmMode(HTIRL, 3, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);
    }
  }
}


Why does that happen? And is there any way to solve it?

thx,
DiMastero

Author:  mightor [ Mon Jul 19, 2010 1:32 pm ]
Post subject:  Re: Delay with HTIRL

I will take a look at this when I get back from vacation. I had a look at the driver and I can't see anything in there that could cause such a delay. You are using ROBOTC 2.02 and driver version 1.5, right?

- Xander

Author:  DiMastero [ Mon Jul 19, 2010 1:55 pm ]
Post subject:  Re: Delay with HTIRL

I just checked it, and I am on version 2.02 and the the latest 3rd party sensors driver (v1.5)

Author:  Jampoz [ Tue Jul 20, 2010 4:41 am ]
Post subject:  Re: Delay with HTIRL

Just like my thread, glad to see it isn't a psp-nx issue then

Author:  DiMastero [ Tue Jul 20, 2010 2:39 pm ]
Post subject:  Re: Delay with HTIRL

Hi there,

I just realized I didn't explain myself well enough when I first talked about the HTIRL delay, by saying the motors didn't react to me pressing the touch sensor right away... The actual problem is that the motors don't stop until about a second after I stop pressing the button... I also tested the lights, in a different program:

Code:
#pragma config(Sensor, S1,     HTIRL,               sensorLowSpeed)
#include "drivers/HTIRL-driver.h"

task main()
{
  int MotorA_cmd = 2;
  int MotorB_cmd = 2;

  ClearTimer(T1);
 
  while (time1[T1] < 10000)
  {
    switch(time1[T1])
    {
       case 1000:
       MotorA_cmd = 2;
       PFcomboDirectMode(HTIRL, 3, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
       wait1Msec(300);
       MotorA_cmd = 0;
       break;
      
       case 3000:
       MotorA_cmd = 2;
       PFcomboDirectMode(HTIRL, 3, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
       wait1Msec(200);
       MotorA_cmd = 0;
      
       case 5000:
       MotorA_cmd = 2;
       PFcomboDirectMode(HTIRL, 3, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
       wait1Msec(50);
       MotorA_cmd = 0;
    }
  }
}


And I still have the same problem... the lights go on at the right times, but they always take about three quarters of a second more than the desired times (300, 200 and 50 Msecs)... I'm not sure if that's helping, but I hope so...

thx,
DiMastero

Author:  mightor [ Wed Jul 21, 2010 10:24 am ]
Post subject:  Re: Delay with HTIRL

I will check this stuff when I get home tomorrow. Pop me a mail (you have the address) to remind me.

- Xander

Author:  mightor [ Thu Jul 22, 2010 11:04 am ]
Post subject:  Re: Delay with HTIRL

K, I've confirmed my original suspicions. The PF commands you are using work as follows:
  • Send a command to the receiver
  • Receiver controls motor
  • Waits for next commands
  • If no new command appears for 1.2 seconds, the command is timed out and the motor is switched off

This is where your 1s delay is coming from. You stop sending "motor run forward" commands but you're not telling it to stop the motors either. I made a small program that shows how you can make this work the way you'd like it to. In other words, stop the motor as soon as you stop pressing the switch.

Code:
#pragma config(Sensor, S1,     HTIRL,               sensorLowSpeed)
#pragma config(Sensor, S4,     TouchSensor,         sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "drivers/HTIRL-driver.h"

task main()
{
  // For now until the batteries run out.
  while (true)
  {
    // Is the button pressed?
    if (SensorValue[TouchSensor])
    {
      // Keep telling the receiver to run the motors while the button is pressed
      while(SensorValue[TouchSensor]) {
        PFcomboPwmMode(HTIRL, 3, CPM_MOTOR_BAK_PWM_7, CPM_MOTOR_FWD_PWM_7);
      }
      // The button is no longer pressed, tell the motors to stop.
      PFcomboPwmMode(HTIRL, 3, CPM_MOTOR_BRAKE, CPM_MOTOR_BRAKE);
    }
  }
}


So there you go. I've tested this on my own NXT and IRLink and it works. The delay between letting go and the motors switching off is not instantaneously but certainly less than 0.2s or so.

- Xander

Author:  Jampoz [ Thu Jul 22, 2010 12:12 pm ]
Post subject:  Re: Delay with HTIRL

This is going to fix my issue too!

Do you think this is something that should be included into the driver documentation in any way?

Author:  DiMastero [ Thu Jul 22, 2010 12:49 pm ]
Post subject:  Re: Delay with HTIRL

Thanks a lot!! the only problem left now is that I don't know how to make the red and blue one move by themselves, and not together..

thx,
DiMastero

Author:  mightor [ Thu Jul 22, 2010 1:41 pm ]
Post subject:  Re: Delay with HTIRL

Sure, I'll add it to the documentation. I have plans to overhaul that driver in a major way in the near future. It was the first driver I ever wrote, so it's not as "clean" as the ones that followed.

- Xander

Author:  DiMastero [ Thu Jul 22, 2010 4:15 pm ]
Post subject:  Re: Delay with HTIRL

Great! could you send me an e-mail, or post it on the forums when you have it?

thx,
DiMastero

Author:  mightor [ Thu Jul 22, 2010 4:17 pm ]
Post subject:  Re: Delay with HTIRL

When a new release of the drivers is out, it will be posted about on these forums and on my blog. See my signature for the URL.

- Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/