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

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

Author:  DiMastero [ Sat Oct 16, 2010 9:04 am ]
Post subject:  Delay with HTIRL using new driver

Hi there,

I wrote this program and tested it, but I get a delay between pressing/releasing the touch sensor and the motors. Furthermore, they don't start and stop at the same time. This is my code:

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

#include "drivers/HTIRL-NG-driver.h"

int speed;

task main() {
  while (true){
   
    PFMotor(pfmotor_S1_C4_A, (ePWMMotorCommand)speed);
    PFMotor(pfmotor_S1_C4_B, (ePWMMotorCommand)speed);
   
    if (SensorValue (TouchSensor) == 1){
      speed = 7;
    }
    else{
      speed = 0;
    }
  }
}


I don't get what's wrong, so does anyone have any suggestions?

thx,
DiMastero

EDIT:

I tried it again using this program:

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

#include "drivers/HTIRL-NG-driver.h"

task main() {
  while (true){
   
    if (SensorValue (TouchSensor) == 1){
      PFMotor(pfmotor_S1_C4_A, (ePWMMotorCommand)7);
      PFMotor(pfmotor_S1_C4_B, (ePWMMotorCommand)7);
    }
    else{
      PFMotor(pfmotor_S1_C4_A, (ePWMMotorCommand)0);
      PFMotor(pfmotor_S1_C4_B, (ePWMMotorCommand)0);
    }
  }
}


It got rid of most of the delay between pressing the button and the motors starting/ stopping, but the delay between the two motors stays. Again, does anyone know how to solve my problem?

thx,
DiMastero

Author:  mightor [ Sat Oct 16, 2010 9:13 am ]
Post subject:  Re: Delay with HTIRL using new driver

They don't stop and start at the same time due to the way the retransmissions work. The driver will retransmit a command several times to ensure that it has arrived (there is no way to verify). This delay is what you are seeing.

In the next release I intend to make this retransmission part a configurable option. However, it is completely according to the Power Function specifications. If you want, you can hack the transmitIR(tSensors link, tByteArray &oBuffer, int channel) function yourself and remove the 3rd, 4th and 5th retransmission commands.

As a work-around, you could use a PFcomboPwmMode() command for both motors at once and then issue the PFMotor commands to ensure the motors continue to run afterwards. You can use PFcomboPwmMode() to stop both motors at the same time as well.

- Xander

Author:  DiMastero [ Sat Oct 16, 2010 10:01 am ]
Post subject:  Re: Delay with HTIRL using new driver

thank's a lot! that explains it. I guess I'll just wait for the next release then, because the other option is a bit to complex for me :p..

Author:  ivanseidel [ Sat Oct 16, 2010 11:34 am ]
Post subject:  Re: Delay with HTIRL using new driver

Yes, it's reetransmiting the same code many times.
I would create another variable, the lastSpeed, and "if the lastSpeed != speed" send the code, and then set the speed to lastSpeed, so, if the speed == lastSpeed, i wouldn't send any command...

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

#include "drivers/HTIRL-NG-driver.h"

int speed=0,lastSpeed=0;

task main() {
  while (true){
    if(lastSpeed!=speed){
        PFMotor(pfmotor_S1_C4_A, (ePWMMotorCommand)speed);
        PFMotor(pfmotor_S1_C4_B, (ePWMMotorCommand)speed);       
        lastSpeed=speed;
    }

   
    if (SensorValue (TouchSensor) == 1){
      speed = 7;
    }
    else{
      speed = 0;
    }
  }
}

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