Serial Transmitter Command

I am new to the whole command thing and im using a serial transmitter to send commands to the TReX DMC01.

Im using the command line 0x80, 0x07, 0x52, 0x7F, 0x7F to make the robot go forward.

Which ones do i have to change to make the robot to go in reverse??

thanks

Hello.

Did you also email this question to us directly? If so, please do not contact us multiple ways without mentioning that you have done so.

The command documentation for the TReX says the following about the Set Motors 1 and 2 command byte:

Where direction is 1 for reverse and 2 for forward.

That means that the command byte will be:
0xD5 = both motors reverse
0xD6 = m2 reverse, m1 forward
0xD9 = m2 forward, m1 reverse
0xDA = both motors forward

If you only have one TReX on your serial line, you can use the simpler Compact Protocol to make both motors go in reverse at full speed:

0xD5, 0x7F, 0x7F

Or you can clear the most significant bit of the command byte and use it in the expanded protocol to do the same thing:

0x80, 0x07, 0x55, 0x7F, 0x7F

- Ben

How do you send a compact command to the TReX??
As far as i can do, I can only do the Expanded protocol. I cant get the Compact protocol to work, what can i use the compact command??

You don’t have to do anything special; the TReX will accept Compact and Extended Protocol commands on the fly. What command bytes are you trying to send the TReX? Please post the Extended Protocol bytes that work for you and the Compact Protocol bytes that do not.

- Ben

The expanded protocol that works for me is 0x80, 0x07, 0x52, 0x7F, 0x7F and 0x80, 0x07, 0x55, 0x7F, 0x7F. None of the compact protocol work.

If the expanded protocol is working for you, you must not be sending the proper compact protocol bytes. Please post the Compact Protocol packet you expect to work but doesn’t.

- Ben

I used the 0xDA, 0x2F, 0x2F and it worked. My main question now is which data byte is the left motor and which one is the right motor? We are building an autonomous robot that uses image processing software. So we need to use a code that will adjust the motors according to how far from the side of the road it is. So if i can figure out how to adjust which motor, that would be fantastic.

I’m glad to hear you have it working. The commands are documented in the user’s guide. Is there something about the documentation that you find confusing?

It’s also very easy for you to see for yourself which data byte is the left motor and which is the right. Just send the command:

0xDA, 0x2F, 0

And see which motor moves (or you can just look to see which motor indicator LED lights up).

If the command to set both motors isn’t so intuitive for you, you can always just send two command packets in a row, one for setting motor 1 and the other for setting motor 2:

0xC2, 0x7F (motor 1 forward at full speed)
0xCA, 0x3F (motor 2 forward at half speed)

- Ben

The part i dont get is the
" Motor 1
direction is specified by bits 1:0 of the command byte and motor 2 direction is specified by bits
3:2 of the command byte. …"
Thats a little confusing to me

That’s the part I elaborated on in an earlier post:

You seemed confused about the speed bytes, too, though. Is that part clear now?

- Ben

Yeah, thank you so much for all your help!! :smiley:

I’m not sure what language you’re programming in, but in case it helps, you could use something like the following C-ish pseudo-code to set the motor speeds:

#define BRAKE 0
#define REVERSE 1
#define FORWARD 2

void setMotorSpeeds(byte m1Dir, byte m1Speed, byte m2Dir, byte m2Speed)
{
  byte command = 0xD0 + 4*m2Dir + m1Dir;
  sendSerialByte(command);  // you need to write this function
  sendSerialByte(m1Speed);
  sendSerialByte(m2Speed);
}

void main()
{
  setMotorSpeeds(FORWARD, 0x7F, REVERSE, 0x2F);
  ...
}

- Ben