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

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

Author:  DiMastero [ Mon Jul 19, 2010 6:01 am ]
Post subject:  HTIRL help

Hi there,

I just got my HTIRL delivered, and I've been looking through some of Xander's drivers/ programs, but I don't get it at all... Could someone post the commands to make different PF motors move (at varying speeds), and the PF lights go on/ off?

thx,
DiMastero

Author:  Jampoz [ Mon Jul 19, 2010 6:52 am ]
Post subject:  Re: HTIRL help

The file is HTIRL-test1.c

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

#include "drivers/HTIRL-driver.h"

 task main {
  int MotorA_cmd = 0;
  int MotorB_cmd = 0;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "IRLink");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);
  eraseDisplay();
  // Test the motors and recievers.
  for (MotorA_cmd = 0; MotorA_cmd < 16; MotorA_cmd++) {
    MotorB_cmd = 15 - MotorA_cmd;
    // PFcomboPwmMode allows you to control the speed of the PF motors.
    // There are 7 forward speeds and 7 reverse speeds, brake and halt
    PFcomboPwmMode(HTIRL, 0, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);
    PFcomboPwmMode(HTIRL, 1, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);
    PFcomboPwmMode(HTIRL, 2, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);
    PFcomboPwmMode(HTIRL, 3, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);
  }

  PlaySound(soundDownwardTones);
  while (bSoundActive) {}

  for (MotorA_cmd = 0; MotorA_cmd < 4; MotorA_cmd++) {
    MotorB_cmd = 3 - MotorA_cmd;
    // PFcomboDirectMode does not allow speed control.  The motor is either
    // going full speed forward or reverse.  You can also brake and float the
    // motor.
    PFcomboDirectMode(HTIRL, 0, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
    PFcomboDirectMode(HTIRL, 1, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
    PFcomboDirectMode(HTIRL, 2, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
    PFcomboDirectMode(HTIRL, 3, (eCDMMotorCommand)MotorB_cmd, (eCDMMotorCommand)MotorA_cmd);
  }
}

Author:  DiMastero [ Mon Jul 19, 2010 7:02 am ]
Post subject:  Re: HTIRL help

thx, but I don't get which command does what, and when I copy/ paste individual commands, I get errors... Could you tell me which command does what, and which have to be combined in order to run?

thx,
DiMastero

Author:  Jampoz [ Mon Jul 19, 2010 9:03 am ]
Post subject:  Re: HTIRL help

Starting Pragma is the tipical RobotC sensor configuration, then there is the include of the needed drivers

The commands can be found inside HTIRL-driver.h

Code:
  CPM_MOTOR_FLOAT = 0,      /*!< Float the motor */
  CPM_MOTOR_FWD_PWM_1 = 1,  /*!< Forward speed 1 */
  CPM_MOTOR_FWD_PWM_2 = 2,  /*!< Forward speed 2 */
  CPM_MOTOR_FWD_PWM_3 = 3,  /*!< Forward speed 3 */
  CPM_MOTOR_FWD_PWM_4 = 4,  /*!< Forward speed 4 */
  CPM_MOTOR_FWD_PWM_5 = 5,  /*!< Forward speed 5 */
  CPM_MOTOR_FWD_PWM_6 = 6,  /*!< Forward speed 6 */
  CPM_MOTOR_FWD_PWM_7 = 7,  /*!< Forward speed 7 */
  CPM_MOTOR_BRAKE = 8,      /*!< Brake the motor */
  CPM_MOTOR_BAK_PWM_7 = 9,  /*!< Reverse speed 7 */
  CPM_MOTOR_BAK_PWM_6 = 10, /*!< Reverse speed 6 */
  CPM_MOTOR_BAK_PWM_5 = 11, /*!< Reverse speed 5 */
  CPM_MOTOR_BAK_PWM_4 = 12, /*!< Reverse speed 4 */
  CPM_MOTOR_BAK_PWM_3 = 13, /*!< Reverse speed 3 */
  CPM_MOTOR_BAK_PWM_2 = 14, /*!< Reverse speed 2 */
  CPM_MOTOR_BAK_PWM_1 = 15  /*!< Reverse speed 1 */


So, for example

PFcomboPwmMode(HTIRL, 2, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);

This one method is telling the Ir receiver on channel 2 (means 3) to give both motors two different commands, stored one two variables, and they can include any number from the upper list

But if you just plug the sensor and make some motors available, then the example will find 'em and move 'em as it scans for all channels and all commands

Author:  DiMastero [ Mon Jul 19, 2010 9:22 am ]
Post subject:  Re: HTIRL help

Thx... I tried it by writing this code:
Code:
#pragma config(Sensor, S1,     HTIRL,               sensorLowSpeed)

task main()
{
  int MotorA_cmd = 7;
  int MotorB_cmd = 7;
 
  while (true)
  {
    PFcomboPwmMode(HTIRL, 2, (eCPMMotorCommand)MotorB_cmd, (eCPMMotorCommand)MotorA_cmd);
  }
}


It didn't work, and I got error reports stating the following:

**Error**:Undifined procedure 'PFcomboPwmMode'.
**Error**:Undifined variable 'eCPMMotorCommand'.'short' assumed.
**Error**:Unmatched left parentheses '('
**Error**:Expected-> ')'. Found 'MotorB_cmd'
**Error**:Expected-> ')'. Found 'MotorB_cmd'
**Error**:Expected-> ';'. Found ','
**Error**:Unexpected scanner token-> ','
**Error**:Unexpected scanner token-> '('
**Error**:Expecting ';' before ')'
**Error**:Unexpected scanner token-> ')'
*Warning*:
Meaningless statement -- no code generated

Author:  Jampoz [ Mon Jul 19, 2010 9:24 am ]
Post subject:  Re: HTIRL help

See? check the first error line, it can't find PFcomboPwmMode, that's because you didn't include the drivers, try including the needed .h file like the code above

Author:  Jampoz [ Mon Jul 19, 2010 9:26 am ]
Post subject:  Re: HTIRL help

You need to follow these instructions when using Xander's drivers

That's because including .h files is essential

Author:  DiMastero [ Mon Jul 19, 2010 9:33 am ]
Post subject:  Re: HTIRL help

What do you mean by including the drivers and .h files? And how should I do that? (I already installed the drivers on your link a few weeks ago)

thx,
DiMastero

EDIT: NEVER MIND; I FOUND THE ANSWER BEING A PIECE OF CODE (HOW STUPID OF ME NOT TO NOTICE IT IN THE BEGINNING!!) THANK YOU

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