View unanswered posts | View active topics It is currently Fri Dec 19, 2014 5:23 am






Reply to topic  [ 15 posts ] 
HiTechnic IR Link Sensor and RobotC 
Author Message
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post HiTechnic IR Link Sensor and RobotC
Hey there,

Has anyone played with the HiTechnic IR Link Sensor? Does anyone have any documentation on how to make this thing work in RobotC?

Thanks,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jul 23, 2008 12:03 pm
Profile WWW
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post 
Hi
Here is a link (http://www.robotc.net/forums/viewtopic.php?t=379) to a previous post with some info on the HiTechnic Link Sensor.
According to this 'JustAnotherNXTHacker' got it to work but never posted the final working version. Perhaps he could be persuaded to do so.

I am also interested in this as I have this very day ordered said sensor.


Fri Jul 25, 2008 3:40 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post 
I am currently working on writing a driver for the IR Link. I was provided with some of the details on the bit encoding scheme used to generate that massive byte array in the code of that post you linked. With that information I will start working on an easy to use interface. Once it's completed I will work on the other modes that the PF motors can be controlled (there are 4 modes in all). The driver will be released for sure, so keep an eye on this post! I will be releasing the driver in chunks as each mode is completed, so you won't have to wait until it is all done.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jul 25, 2008 3:50 am
Profile WWW
Novice

Joined: Sat Apr 12, 2008 11:09 am
Posts: 56
Location: holland
Post 
Helo,

I have the basic commands working on channel 1 and 2, but i can not find any logic in it.

Hi-technics told me there is not a simple way to program using the PF-data sheet.

I will post my program later


Mon Aug 04, 2008 5:05 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post 
Hiya NXT,

Yeah, I have the comboDirectMode working nicely. I am now working on comboPwmMode but I still have a few bugs to iron out. Will keep you posted with my progress.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Aug 04, 2008 11:02 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: HiTechnic IR Link Sensor and RobotC
I have a working version of the driver posted on my blog, you can read the article here: LINK.

The link to the code is at the bottom of the page.

Enjoy.

Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Aug 14, 2008 2:21 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: HiTechnic IR Link Sensor and RobotC
hi,
great if you'll manage to write a convenient driver for the IR-link sensor.

To this I have some suggestions:

for 1 nxt motor you use
Code:
motor[0]=80; // Motor at port 0 [motorA], speed=80 


with other C libraries you maybe will use for the same purpose
Code:
motor(0,80); // alternative C code


if you got 4 RCX's (0,1,2,3) and a motor at RCX[3] -Port 0 (A) via IR-Link , there could be a motor command (RCXmotor) like:

Code:
RCXmotor(3,0,-80);


at RCX(1), but Port 2 (C), and backwards::

Code:
RCXmotor(1,2,-80);


3 motors (0,1,2) with built-in IR-receivers (power motors), could work this way:

Code:
Powermotor(0,100);
Powermotor(1,-80);
Powermotor(2,50);


and with 5 train motors this way:

Code:
Trainmotor(0,100);
Trainmotor(1,100);
Trainmotor(2,-50);
Trainmotor(3,-20);
Trainmotor(4,100);


If you'll manage this, that would be one giant leap for mankind... :D

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Thu Aug 14, 2008 5:34 pm, edited 1 time in total.



Thu Aug 14, 2008 2:54 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: HiTechnic IR Link Sensor and RobotC
Ford,

Those are some nice suggestions. I will definately look into them! They'll be added as wrappers around my base functions. There would have to be some kind of task that monitors these variables.

As for speeds, there are only 7 steps, excluding brake and coast. It is not a 0-100 variable like with the normal motors. I'll have to figure something out for that :)

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Aug 14, 2008 3:39 pm
Profile WWW
Rookie

Joined: Sun Dec 02, 2007 5:29 pm
Posts: 1
Post Re: HiTechnic IR Link Sensor and RobotC
And just to expand on the knowledge, My cobbled together ComboPWM Driver is here:
http://www.brickshelf.com/gallery/Parax/NXTSample/RobotC/pwm_0-1-6.c (with comments!)


But if your good at reading code or like a challenge try this :) :lol:

Code:
byte PFB[17];

void PFComboPWM(byte Ch, byte OutR, byte OutB){
    byte PFBi=0;
    byte PFBBi=0;
    byte N[4];
    byte Ni=0;
    byte NBi=0;
    for(PFBi=0;PFBi<17;PFBi++){PFB[PFBi]=0x00;}
    PFBi=0;
    N[0]=0x4+Ch;
    N[1]=OutB;
    N[2]=OutR;
    N[3]=0xF;
    N[3]=N[3]^N[0]^N[1]^N[2];
    PFB[0]=16;
    PFB[1]=0x02;
    PFB[2]=0x42;
    PFB[3]=0x80;
    for(Ni=0;Ni<4;Ni++){
        for(NBi=0;NBi<4;NBi++){
            PFB[4+(PFBBi/8)]=PFB[4+(PFBBi/8)]|(128>>(PFBBi%8));
            if(N[Ni]&(8>>NBi)){PFBBi=PFBBi+5;}else{PFBBi=PFBBi+3;}}}
    PFB[4+(PFBBi/8)]=PFB[4+(PFBBi/8)]|(128>>(PFBBi%8));
    PFB[14]=0x11;
    PFB[15]=0x02;
    PFB[16]=0x01;}

task main(){
    SensorType[S1]=sensorI2CCustom9V;
    nI2CBytesReady[S1]=0;
    int OutR=0;
    int OutB=0;
    int ch=0;
    for(OutR=0;OutR<16;OutR++){OutB=15-OutR;
        for(ch=0;ch<4;ch++){
            PFComboPWM(ch,OutR,OutB);
            while(nI2CStatus[S1]==STAT_COMM_PENDING){}
            sendI2CMsg(S1,PFB[0],0);
            wait1Msec(20);}
        wait10Msec(60);}}


More to come. maybe.
Parax.


Thu Aug 14, 2008 4:18 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: HiTechnic IR Link Sensor and RobotC
mightor wrote:
As for speeds, there are only 7 steps, excluding brake and coast. It is not a 0-100 variable like with the normal motors.

hello,
I didn't know that - but I think 7 steps should be enough!
but BTW, there could be another sophisticated thing be done:
simultaneously reading of the values of a rcx rotation sensor attached to the related motor (RCX-motorA /RCX-sensor1 ....) 8) 8) 8)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Aug 14, 2008 5:28 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: HiTechnic IR Link Sensor and RobotC
Ford,

No RobotC driver for RCX has been made yet. I will need one to test with first.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Aug 15, 2008 1:04 am
Profile WWW
Novice

Joined: Sat Apr 12, 2008 11:09 am
Posts: 56
Location: holland
Post Re: HiTechnic IR Link Sensor and RobotC
Hello,

I copied some code of Parax and made an include file of it, so you can easy use PFcomboPWM within the program by calling one procedure.

here is some sample code of how to do that
Code:
/*  RobotC-HTLink-Power Function PWM Mode
    Version: 0.1.6
    Date: 14/08/08
    Author: Mike Hatton
    Contact: Parax77ATgooglemailDOTCom
    Usage:*/

#include "PFmotorPWM.h";
task main()
{
   nMotorEncoder[motorA]=0;
   bMotorReflected[motorA]=true;
   nMotorEncoder[motorB]=0;
   int speedB=0,speedR=0,cha=1;
   while(1)
  {
    speedR=nMotorEncoder[motorA]/5;
    speedB=nMotorEncoder[motorB]/5;
    PFComboPWM(S1,cha, speedB, speedR );//send speed. use parameters for
                                             //sensorport,channel,speed blue motor,speed red motor
  }
}


Call the PFComboPWM procedure each time when you want to change a speed and for all four channels.
speed value 1 to 7 for forward,
speed value -1 to -7 far reverse,
speed value 0= float
speed values outside -7 to +7 = brake.


here is the include file
Code:
/*  include program for RobotC-HTLink-Power Function PWM Mode
    Version: 1.0
    Date: 26/08/08
    Author: Gerrit Boomsma
    Contact:
    Usage: give easy use for PFmotors in RobotC userprograms
*******************************************************************************************
COPYED code from Mike Hatton and added code to it to easy use it in user programs.
/*  RobotC-HTLink-Power Function PWM Mode
    Version: 0.1.6
    Date: 14/08/08
    Author: Mike Hatton
    Contact: Parax77ATgooglemailDOTCom
    Usage:
*********************************************************************/

int i;
int sensorport=0;
int index1=0,index2=0;
int array[4][2];
#pragma autoStartTasks


byte PFB[17];

int speedvalue(byte speed)//convert selected speed to speed for PFmotor
{
   if (speed==0)//if selected speed is 0, motor will float
   {
      return 0;
   }
   else if (speed>0&&speed<8)//motor runs forward at selected speed 1 to 7
   {
     return speed;
        }
   else if (speed<0&&speed>-8)//motor runs reverse at selected speed -1 to -7
   {
      return speed+16;
   }
   return 8; //if speed selected other than -7 to +7, motor will brake.
}

// put selected speeds in an array.
void PFComboPWM(const tSensors sensorport,byte Channel, byte OutX, byte OutY)
{
   array[Channel-1][0]=OutX;
        array[Channel-1][1]=OutY;
}

// send data to PF receiver. Most code copyed from Mike Hattom
void sendIR(const tSensors sensorport,byte chan, byte OutX, byte OutY)
{
   nI2CBytesReady[sensorport] = 0;
   byte PFBi = 0; //PFByte Counter
   byte PFBBi = 0; //PFByte Bit Counter
   byte N[4]; //Nibble Array
   byte Ni = 0; //Nibble Counter
   byte NBi = 0; //Nibble Bit Counter
   //Clear PFB[] Array
   for (PFBi = 0; PFBi < 17; PFBi++)
   {
      PFB[PFBi] = 0x00;
   }
   PFBi = 0;
   //Populate Nibbles
   N[0] = 0x4+chan; //PWM Mode + (0-3)
   N[1] = speedvalue(OutX); //(0-15)
   N[2] = speedvalue(OutY); //(0-15)
   N[3] = 0xF; //XOR CRC
   N[3] = N[3]^N[0]^N[1]^N[2];//XOR CRC
   //Write PFB[0-3] (Fixed)
   PFB[0] = 16; //PFByte Length
   PFB[1] = 0x02; //Sensor Address
   PFB[2] = 0x42; //Write to Address
   PFB[3] = 0x80; //Start Bit
   //Write PFB[4-13] From Nibbles
   for (Ni = 0 ; Ni < 4 ; Ni++)//For Nibble 1 to 4
   {
      for (NBi = 0 ; NBi < 4 ; NBi++)//For Nibble Bit = 1 to 4
      {
         PFB[4+(PFBBi/8)] = PFB[4+(PFBBi/8)]|(0x80>>(PFBBi%8));   
         if (N[Ni]&(0x8>>NBi))   
         {
            PFBBi = PFBBi + 5; // add High = 5
         }
         else
         {
            PFBBi = PFBBi + 3; //add Low = 3
         }   //Next NibBit
      }   //Next Nibble
   }
   PFB[4+(PFBBi/8)] = PFB[4+(PFBBi/8)]|(0x80>>(PFBBi%8));
   PFB[14] = 0x11; //Length
   PFB[15] = 0x02; //PF Mode
   PFB[16] = 0x01; //Xmit
       for (i=0; i<4; i++)
       {
             while (nI2CStatus[sensorport] == STAT_COMM_PENDING)
        {}
           sendI2CMsg(sensorport, PFB[0], 0); // Send PFBytes
      }
}
task xmit()
{
      //   initialising
     SensorType[S1] = sensorI2CCustom9V;
     nI2CBytesReady[S1] = 0;
     //   clearing the array
     for (index1=0; index1<5;index1++)
    {
          for (index2=0; index2<3;index2++)
          array[index1][index2] = 0;
    }
     int xmitchannel=0,xmitblue=0,xmitred=0;
     while(1)
    {
          xmitblue=array[xmitchannel][0]; //load blue motor speed
     xmitred= array[xmitchannel][1]; //load red motor speed
          sendIR(sensorport,xmitchannel,xmitblue,xmitred);//send param to conversion code

     xmitchannel++; //swapp channels 1-4
     if(xmitchannel>3)
     xmitchannel=0;
     wait1Msec(20);
    }
}


Anyone who can improve this code or who can make some kind of driver from it?


Wed Aug 27, 2008 11:14 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: HiTechnic IR Link Sensor and RobotC
Version 1.1 of my driver is out now. The only thing that has changed is that the code no longer has a main task without being explicitly enabled with a define at the top of the file. This stops it from causing issues when used as an include :)

Edit: you can download it here.
Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Aug 27, 2008 11:17 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: HiTechnic IR Link Sensor and RobotC
Great Work :-)

You may also want to post your code under the projects section, so others could find it in the future.

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Aug 27, 2008 4:26 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: HiTechnic IR Link Sensor and RobotC
whow, man, this is really sophisticated:
Code:
PFB[4+(PFBBi/8)] = PFB[4+(PFBBi/8)]|(0x80>>(PFBBi%8)); 
:shock:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Wed Aug 27, 2008 4:45 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.