Author Topic: MD25 Motor Driver encoder read problem  (Read 3171 times)

0 Members and 1 Guest are viewing this topic.

Offline helicopterTopic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
MD25 Motor Driver encoder read problem
« on: December 05, 2014, 10:00:19 PM »
Hi Guys

I am having troubles getting the motor driver to read the encoder for a EMG30 motor from Devantech.
All other data requests can be returned to USB to display on hyperterminal no problems but when it comes to receiving 4 bytes of data I am stuck!
I have tried most options (arrays, etc) but have yet to crack it! I am missing something.  I have searched and used other examples from the internet all without success.
/*_________________________________________________________

The Data sheet for the MD25:

GET ENCODER 1, GET ENCODER 2 or GET ENCODERS
When a read encoder command is issued the MD25 will send out 4 bytes high byte first, which should be put together to form a 32 bit signed number. For example a GET ENCODER 1 command may return 0x00,0x10,0x56,0x32.

So declare a 32 bit signed variable in your program, for C:
long result;
 result = serin() << 24;    // (0x00 shifted 24 bits left, effectively * 16777216)
 result += serin() << 16;   // (0x10 shifted 16 bits left, effectively * 65536)
 result += serin() << 8;    // (0x56 shifted 8 bits left, effectively * 256)
 result += serin();         /  (0x32)
 
result now equals 1070642 decimal or 0x105632 hex. If the highest bit was set then it would be -ve.
 read encoders will send encoder count 1 and then encoder count 2 but is put together in exactly the same way. The registers can be zeroed at any time by writing 0x35 to the MD25.

*/______________________________________



The encoder read function example from Robot-electronics.co.uk for serial connection is

long readEncoder(){                        // Function to read and display the value of both encoders, returns value of first encoder
  long result1 = 0;
  long result2 = 0;
  Serial.write(CMD);
  Serial.write(READENCS);
  while(Serial.available() < 8){}          // Wait for 8 bytes, first 4 encoder 1 values second 4 encoder 2 values
  result1 = Serial.read();                 // First byte for encoder 1, HH.
  result1 <<= 8;
  result1 += Serial.read();                // Second byte for encoder 1, HL
  result1 <<= 8;
  result1 += Serial.read();                // Third byte for encoder 1, LH
  result1 <<= 8;
  result1  += Serial.read();               // Fourth byte for encoder 1, LL
  result2 = Serial.read();
  result2 <<= 8;
  result2 += Serial.read();
  result2 <<= 8;
  result2 += Serial.read();
  result2 <<= 8;
  result2 += Serial.read();

A month of failures and I have no other option but to ask for help!

Does anyone have a code for this function to use to grab 4 bytes of data and return a value for use as a counter to get a motor to stop at a given angle!
I am using the Axon 2 with the Devantech MD25 driver.

The joys of programing!
Otherwise the Axon 2 is a great piece of kit, 5 stars for that bad boy SoR!!

Thanks Heli



Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: MD25 Motor Driver encoder read problem
« Reply #1 on: December 06, 2014, 08:16:32 AM »
Both those algorithms look ok and are effectively doing the same thing. The first one shifts they byte to the right place before adding to the result. The second adds each byte into the result and repeatedly shifts the result - ie the first byte will get shifted 3 times and 3 x 8 = 24.

You dont say what libraries you are using eg WebbotLib, WebbotLibStudio, Arduino, Atmel AVR Studio 6, WinAVR. or something else.
The reason for asking is that you may actually be building up the 'long' ok - but falling down in the way that you are trying to print it as a number over the USB port. So would be interesting to know how you are doing that.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


Get Your Ad Here

data_list