NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Discussion specific to the intelligent brick, sensors, motors, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by HaWe »

thx, but that indeed is far too elaborated to me - I have no idea how to program this.
Maybe you can try...?
Give me your code, and I will try it out!
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by h-g-t »

Wish I could provide some code but it is way beyond my computing skills!

I was just passing on some stuff I found in the hope that it might help shed some light on the problem.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mattallen37 »

That is all just referring to the commands and such that the controller is capable of doing.

What specifically so you want to be able to do? Do you just want simple speed and direction control?

It is hard to program a fool proof program, without the hardware to test it.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mattallen37 »

Here is an example you could try, using both the flag system and the waiting. I obviously don't have the hardware to test it, but you can try it for yourself.

Code: Select all

#define TetrixPort S1        //Tetrix controller Port
#define TetrixAddr 0x02      //Tetrix controller Address

#define TetrixWaitTime 50    //How many ms to wait (at a minimum) before allowing another command to be sent

bool FlagUpdateTetrix=false; //Set to true to send the commands
byte TetrixControlData[];    //contains the control data

//This function does the lower level I2C communication, and should not ever need adjustments.
void TetrixController(byte port, byte addr, byte reg, byte data[])
{
  byte result = -1;            // default: error value
  byte cmdbuf[];               // register number holder
	int loop, n, nByteReady;

  ArrayBuild(cmdbuf, addr, reg, data);

  loop = STAT_COMM_PENDING;              //Wait until bus is free
  while (loop == STAT_COMM_PENDING ){    //        ''
    loop = I2CStatus(port, nByteReady);  //        ''
  }                                      //        ''

  n = I2CWrite(port, 0, cmdbuf);        //When the I2C bus is ready, send the message you built
  while (I2CStatus(port, nByteReady) ==  STAT_COMM_PENDING); //Wait until bus is free
}

//This is the task that updates the controller
task UpdateTetrixController(){
  while(true){
    until (FlagUpdateTetrix==true);   //Wait until the flag is set true
    TetrixController(TetrixPort, TetrixAddr, 0x44, TetrixControlData); //Send the commands
    FlagUpdateTetrix=false;           //Reset the flag back to false
    Wait(TetrixWaitTime);             //Wait the necessary amount of time for the controller's sake
  }
}

task main(){
  SetSensorLowspeed(TetrixPort);         //Set up the port for I2C
  TetrixControlData[0]=0x00;             //Put motor 1 into speed control mode
  TetrixControlData[3]=0x00;             //Put motor 2 into speed control mode
  start UpdateTetrixController;          //start the update task
  while(true){
    int Motor_1_Speed = Random(200)-100; //Choose a random speed from -100 to 100
    int Motor_2_Speed = Random(200)-100; //Choose a random speed from -100 to 100

    TetrixControlData[1]=Motor_1_Speed;  //-100 to 100. 0 is brake. -128 is float.
    TetrixControlData[2]=Motor_2_Speed;  //-100 to 100. 0 is brake. -128 is float.

    FlagUpdateTetrix=true;               //Allow NXT to update controller
    Wait(1000);                          //Wait until the next random speed
  }
}
Basically, this should set the motors to random speeds and directions every 1000ms (1 second).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by HaWe »

thx matt for your efforts!
I tried your program right now, it says "Running" but it does quite nothing: no single motor action at all :(
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by mattallen37 »

You're welcome for trying.

Oh well, I guess you'll just have to wait until John releases them, unless you figure it out beforehand.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: I²C drivers for Hitechnic Tetrix motor muxer ?

Post by HaWe »

Update:
I meanwhile managed reading through probably all available manuals for NXT-G and RobotC, and this is the disappointing result:
Neither in NXT-G nor in RobotC are provided blocks or routines or code examples for a quick frequently reading of the Tetrix encoder values. So I guess the reason is that it's simply not possible to do it in any programming language because of HT controller internals.
Therefore, a use for odometry is absolutely not possible with the HT Tetrix motor controller and the HT Tetrix encoders.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests