BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 9:19 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Mon Sep 26, 2011 1:51 pm 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
Here we are a year later and I'm finally getting back to this sub-project... and it appears I'm in the same hole I was in last July. The roboclaw will still not stop on command. The status 1 LED blinks when the command is issued, but the motor keeps on keeping on. The motor also still jumps to full speed when the reset is pressed.

Since it has been so long, the pertinent data has changed.
Win7 x64 Home, all updates current
Studio 2.0.0.15
Roboclaw version obtained with command 21
Code:
RoboClaw 5A V1.3.9

I bought this in spring of last year and sent it in June/July 2010 for a firmware update.

The following code reads the version and position, starts the motor, reads the speed, and then ends. I've tried commands 0 and 6 with the same results. I'm currently working on closed loop speed (CMD 32), and will update what I find there.

I was unsure if I should bring this thread back from the dead, or start a new one. Since it is the same roboclaw and the issues were never actually resolved, I went this way. I also never got confirmation if I could combine the long variables on the commands. Instead of speed.byte3, speed.byte2, etc, just use speed. Not that pressing as I can give it a try, was just looking for confirmation.

Code:
MAIN
'   READ AND DISPLAY ROBOCLAW VERSION
   R1COMMAND = 21                  
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [STR VERSION\32\0, R1CRC]
   SEROUT S_OUT, I38400, [0, "VERSION          ", STR VERSION\32\0, CR]
   SEROUT S_OUT, I38400, ["VERSION CRC      ", DEC R1CRC, CR, CR]

   PAUSE 100

'   READ AND DISPLAY CURRENT POSITION, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 16
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1DIST.BYTE3, R1DIST.BYTE2, R1DIST.BYTE1, R1DIST.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["POSITION ", DEC R1DIST, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1DIST.BYTE3 + R1DIST.BYTE2 + R1DIST.BYTE1 |
          + R1DIST.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR, CR]
   
   PAUSE 100
'   DRIVE M1 FORWARD WITH A BYTE VALUE
   R1COMMAND = 0
   BYTESPEED = 64
   R1CRC = (R1ADDRESS + R1COMMAND + BYTESPEED) & 0x7F
   HSEROUT [R1ADDRESS, R1COMMAND, BYTESPEED, R1CRC]

   PAUSE 1000
      
'   READ AND DISPLAY CURRENT SPEED, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 18
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, R1SPEED.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["SPEED    ", DEC R1SPEED, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 |
          + R1SPEED.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC]

   PAUSE 1000   

'   DRIVE M1 FORWARD WITH A BYTE VALUE
   R1COMMAND = 0
   BYTESPEED = 0
   R1CRC = (R1ADDRESS + R1COMMAND + BYTESPEED) & 0x7F
   HSEROUT [R1ADDRESS, R1COMMAND, BYTESPEED, R1CRC]
END

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Mon Sep 26, 2011 2:16 pm 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
More info, but I'm not sure exactly what it means. The following runs the motor up to near full speed in a few steps and then runs it back down to a stop.
Code:
   R1COMMAND = 0
   FOR COUNTER = 0 TO 120 STEP 20
      BYTESPEED = COUNTER
      R1CRC = (R1ADDRESS + R1COMMAND + BYTESPEED) & 0x7F
      HSEROUT [R1ADDRESS, R1COMMAND, BYTESPEED, R1CRC]
      PAUSE 2000
   NEXT
   FOR COUNTER = 120 TO 0 STEP -20
      BYTESPEED = COUNTER
      R1CRC = (R1ADDRESS + R1COMMAND + BYTESPEED) & 0x7F
      HSEROUT [R1ADDRESS, R1COMMAND, BYTESPEED, R1CRC]
      PAUSE 2000
   NEXT
   


This code runs the motor up to near full speed in a few steps, reads the encoder speed, but the motor remains at full speed indefinitely.

Code:
   R1COMMAND = 0
   FOR COUNTER = 0 TO 120 STEP 20
      BYTESPEED = COUNTER
      R1CRC = (R1ADDRESS + R1COMMAND + BYTESPEED) & 0x7F
      HSEROUT [R1ADDRESS, R1COMMAND, BYTESPEED, R1CRC]
      PAUSE 2000
   NEXT
   
'   READ AND DISPLAY CURRENT SPEED, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 18
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, R1SPEED.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["SPEED    ", DEC R1SPEED, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 |
          + R1SPEED.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC]

   FOR COUNTER = 120 TO 0 STEP -20
      BYTESPEED = COUNTER
      R1CRC = (R1ADDRESS + R1COMMAND + BYTESPEED) & 0x7F
      HSEROUT [R1ADDRESS, R1COMMAND, BYTESPEED, R1CRC]
      PAUSE 2000
   NEXT
END

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Mon Sep 26, 2011 2:48 pm 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
Sorry to stack this up, just posting it as I try it. I ran the motor near full speed using CMD 36 with the same results as above (for the most part.) If the stop follows the start, it will actually stop. If I read the encoder speed (18), fast speed (30), or position (16) after starting, it never stops.

The reason I say 'for the most part' above is because the motor shook pretty badly before actually stopping. I'm guessing some PID tuning will fix that, so I'll say the test had the same results for now.

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Mon Sep 26, 2011 8:37 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
I'm probably going to miss some things in your posts but first:

Pressing reset on the old revisions of the RoboClaw(green PCB) will cause the motor driver to remain in the last state it was in. If the PWM is in the on state when you press reset then the motors are going to surge to 100% power. Reset stops the processor. We can't do anything about this on the old revision. We've upgraded the new revisions(red PCB) to include a third state so when reset is pressed the motors are disconnected from the drive circuit and will go into freewheel and eventually cost to a stop(how long it takes will depend on your motors friction).

If after sending a command to the roboclaw a following command fails to work correctly then I'd say the problem is caused by garbage left over in the serial buffers(either on the roboclaw or on the controlling device).

First check to make sure your program is even getting to the second for next loop properly(add a serout inside the for nbext loop and make sure your program is getting there and isn't freezing for some reason).

Then add a second read command after the first one and see if that one works. If the second read back command fails then something is happening to the serial buffer.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Tue Sep 27, 2011 8:41 am 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
I'm really confused now. I came in this morning and the motor runs up and down without any issue using command 6. Nothing changed other than the time. It's still sitting in the same corner of my desk. It has to be more than a fluke that a year later I was having the same issues. Anyways, I moved over to CMD 35. I think I've typed 32 and 36 at this point, but 35 IS the command I'm using for encoder controlled speed. 32 was the old command (figured out that I was using the old manual with the new firmware.) 36 was a type-o as I have no motor 2.

The following code stopped the motor (other than the vibration due to PID tuning), but had strange results. For some reason, it was not displaying correctly in the terminal window. Only the first 2 or 3 characters of the SEROUT in the FOR...NEXT loop were jumbled. Everything else, before and after, came through complete. It did this on the ramp up and the ramp down.

Partial output from terminal window
Code:
POSITION 0
STATUS   0
CHECKSUM 16
CRC CALC  16

ƒ©¤RENT SPEED 0
ƒ©¤RENT SPEED 10000
ƒ©¤RENT SPEED 20000
ƒ©¤RENT SPEED 30000
ƒ©¤RENT SPEED 40000
ƒ©¤RENT SPEED 50000
SPEED    48939
STATUS   0
CHECKSUM 124
CRC CALC  124


pertinent code
Code:
'   READ AND DISPLAY CURRENT POSITION, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 16
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1DIST.BYTE3, R1DIST.BYTE2, R1DIST.BYTE1, R1DIST.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["POSITION ", DEC R1DIST, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1DIST.BYTE3 + R1DIST.BYTE2 + R1DIST.BYTE1 |
          + R1DIST.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR, CR]
   PAUSE 100

'   DRIVE M1 FORWARD SIGNED SPEED
   R1COMMAND = 35
   FOR COUNTER = 0 TO 50000 STEP 10000
      R1SPEED = COUNTER
      R1CRC = (R1ADDRESS + R1COMMAND + R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 |
             + R1SPEED.BYTE0) & 0x7f
      HSEROUT [R1ADDRESS, R1COMMAND, R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, |
             R1SPEED.BYTE0, R1CRC]
      SEROUT S_OUT, I38400, ["CURRENT SPEED ", DEC R1SPEED, CR]
      PAUSE 2000
   NEXT

'   READ AND DISPLAY CURRENT SPEED, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 18
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, R1SPEED.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["SPEED    ", DEC R1SPEED, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 |
          + R1SPEED.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR]

'   DRIVE M1 FORWARD SIGNED SPEED
   R1COMMAND = 35
   FOR COUNTER = 50000 TO 0 STEP -10000
      R1SPEED = COUNTER
      R1CRC = (R1ADDRESS + R1COMMAND + R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 |
             + R1SPEED.BYTE0) & 0x7f
      HSEROUT [R1ADDRESS, R1COMMAND, R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, |
             R1SPEED.BYTE0, R1CRC]
      SEROUT S_OUT, I38400, ["CURRENT SPEED ", DEC R1SPEED, CR]
      PAUSE 2000
   NEXT
   
'   READ AND DISPLAY CURRENT POSITION, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 16
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1DIST.BYTE3, R1DIST.BYTE2, R1DIST.BYTE1, R1DIST.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["POSITION ", DEC R1DIST, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1DIST.BYTE3 + R1DIST.BYTE2 + R1DIST.BYTE1 |
          + R1DIST.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR, CR]
   PAUSE 100   
END   

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Tue Sep 27, 2011 10:02 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Could be a loose connection. If the serial data gets corrupted the CRC won't match and the command will be ignored. After you read back the speed you may need to add a short delay before sending a new command. It's possible the RoboClaw isn't ready and gets the first byte corrupted causing the whole command to fail. You could be right on the edge. This shouldn't happen since it's buffered, but it's something to check.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Tue Sep 27, 2011 11:01 am 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
I'm starting to think it's noise. I just noticed something else strange; my received CRC is sometimes off by 2. i.e. 108 when I calculated 106 from the data received. This is true for the speed and position readings. The error is always 2, but is random on when it pops up.

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Tue Sep 27, 2011 2:22 pm 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
I don't have a logic analyzer, but I do have an 'antique' Tek 222 scope. The signal looks clean. The Version CRC always comes back as 51. I haven't checked to see if that is correct, but since the display is always correct, I assume it is.

Whenever the received CRC doesn't match the calculated CRC, the calculated is always 2 LESS than the received, so it looks like I'm missing something something, but why always 2?

I also cannot get the roboclaw to take my PID values. If I run a CMD 28,the motor will not run until I reset the roboclaw. I've tried transmitting the defaults, and with the same results. The roboclaw still responds to requests for speed and position, but will not run without being reset.

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Wed Sep 28, 2011 8:32 am 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
A couple of updates. I picked up a TDS2014 oscope last night! Very excited about my new (old) toy. Bigger screen, color, 4 channels, and actually lighter than the ol' 222. First thing this morning I looked for noise, and the largest spikes are less than 0.25V from what I can see. To test this, I just run an infinite loop requesting the position or speed. That way I can get the same wave form over and over.

If you notice, my code has pauses after every command sent to the roboclaw, I wasn't sure how fast it could respond, so those started at 100ms, but are down to 10ms after several trials and it doesn't seem to make a significant difference.

Since yesterday morning, the roboclaw seems to be behaving other than the missing 2 on a few reads and the acceptance of the PID gains. I have tried to set PID gains on both channels. If I set channel 1, the motor will not run on channel 1 until the roboclaw is reset (which loses the gains). The same is true on channel 2. If I set the gains on channel 1 and run channel 2, the motor runs... and vice versa. Is there anything glaringly wrong with the below code used to set PID gains?

Also, channel 2 behaves very differently. Channel 1 was unstable at lower speeds while channel 2 is slow to respond. I would think they should be the same since the only change was moving the wires over.

Code:
'   SET PID VALUES
R1COMMAND = 28
R1CRC = (R1ADDRESS + R1COMMAND + |
       R1KD.BYTE3 + R1KD.BYTE2 + R1KD.BYTE1 + R1KD.BYTE0 + |
       R1KP.BYTE3 + R1KP.BYTE2 + R1KP.BYTE1 + R1KP.BYTE0 + |
       R1KI.BYTE3 + R1KI.BYTE2 + R1KI.BYTE1 + R1KI.BYTE0 + |
       R1QP.BYTE3 + R1QP.BYTE2 + R1QP.BYTE1 + R1QP.BYTE0) & 0x7F
HSEROUT [R1ADDRESS, R1COMMAND, |
       R1KD.BYTE3, R1KD.BYTE2, R1KD.BYTE1, R1KD.BYTE0,   |
       R1KP.BYTE3, R1KP.BYTE2, R1KP.BYTE1, R1KP.BYTE0,   |
       R1KI.BYTE3, R1KI.BYTE2, R1KI.BYTE1, R1KI.BYTE0,   |
       R1QP.BYTE3,R1QP.BYTE2, R1QP.BYTE1, R1QP.BYTE0,   R1CRC]
PAUSE 10
SEROUT S_OUT, I38400, ["PID CRC ", DEC R1CRC, CR]

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Wed Sep 28, 2011 9:51 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Post your whole program. The only thing I can think of as far as the 2 is concerened is something else in your code is corrupting what is being sent to the roboclaw.

You can also try using a different baudrate to communicate and see if you still get a random 2 added/subtracted. If that happens then it isn't noise. It would have to be something in your code itself.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Wed Sep 28, 2011 12:06 pm 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
You are correct! I originally started out with constants for the PID gains and QPPS. I'm not sure why, but I couldn't get it to compile and would get an error for R1KP.BYTE3. Basically it didn't like separating a constant into bytes. (I was going to ask about that one later as I have no need to change PID gains while executing, so I could free up quite a bit of variable space.) To keep things going, I changed them all to long variables and immediately assigned the variable, forgetting that the CLEAR statement was just a few lines below.

Once I encounter a problem, I very rarely try to troubleshoot it in the real program. I'll build a snippet of code that focuses on the problem. Since I'm working with less code, it changes rather rapidly as I try to figure out what is going on. The current code is running channel 2 with all assignments after the CLEAR. This also appears to have corrected the checksum issue. I really can't explain that one. I'm not missing the random 2 anymore though. I am, however, still getting the odd characters on the terminal window. Since I only use the terminal for troubleshooting, I'll say that the roboclaw is working like I want at this point.

FWIW, I tried both 38400 and 19200 bauds before even posting.

Code:
CR         CON      13         'Carriage return for debug
R1ADDRESS   CON      128         'Serial address for RoboClaw

R1COMMAND   VAR      BYTE
R1ACCEL      VAR      LONG      'ROBOCLAW 1 ACCELERATION QP/S^2
R1SPEED      VAR      SLONG      'ROBOCLAW 1 SPEED (QUAD COUNTS)
R1DIST      VAR      LONG      'ROBOCLAW 1 DISTANCE (QUAD COUNTS)
R1CRC      VAR      BYTE      'ROBOCLAW 1 CRC CHECKSUM
R1BUFFER   VAR      BYTE      'ROBOCLAW 1 BUFFER
R1STATUS   VAR      BIT         'ROBOCLAW 1 RUNNING STATUS
VERSION      VAR      BYTE[32]
BYTESPEED   VAR      BYTE
R1KD      VAR      LONG
R1KP      VAR      LONG
R1KI      VAR      LONG
R1QP      VAR      LONG

RUNPB      VAR      IN6
CLEARPB      VAR      IN8

CLEAR

R1KD = 128
R1KP = 286
R1KI = 256
R1QP = 50000

ENABLEHSERIAL1
SETHSERIAL1 H19200
PAUSE 1000

'READ AND DISPLAY ROBOCLAW VERSION
R1COMMAND = 21                  
HSEROUT [R1ADDRESS, R1COMMAND]
HSERIN [STR VERSION\32\0, R1CRC]
SEROUT S_OUT, I38400, [0, "VERSION          ", STR VERSION\32\0, CR]
SEROUT S_OUT, I38400, ["VERSION CRC      ", DEC R1CRC, CR, CR]
PAUSE 10

'SET PID VALUES
R1COMMAND = 29
R1CRC = (R1ADDRESS + R1COMMAND + |
       R1KD.BYTE3 + R1KD.BYTE2 + R1KD.BYTE1 + R1KD.BYTE0 + |
       R1KP.BYTE3 + R1KP.BYTE2 + R1KP.BYTE1 + R1KP.BYTE0 + |
       R1KI.BYTE3 + R1KI.BYTE2 + R1KI.BYTE1 + R1KI.BYTE0 + |
       R1QP.BYTE3 + R1QP.BYTE2 + R1QP.BYTE1 + R1QP.BYTE0) & 0x7F
HSEROUT [R1ADDRESS, R1COMMAND, |
       R1KD.BYTE3, R1KD.BYTE2, R1KD.BYTE1, R1KD.BYTE0,   |
       R1KP.BYTE3, R1KP.BYTE2, R1KP.BYTE1, R1KP.BYTE0,   |
       R1KI.BYTE3, R1KI.BYTE2, R1KI.BYTE1, R1KI.BYTE0,   |
       R1QP.BYTE3,R1QP.BYTE2, R1QP.BYTE1, R1QP.BYTE0,   R1CRC]
PAUSE 10

'CLEAR ENCODER VALUES
CLEARENC
   R1COMMAND = 20
   R1CRC = (R1ADDRESS + R1COMMAND) & 0x7F
   HSEROUT [R1ADDRESS, R1COMMAND, R1CRC]
   SEROUT S_OUT, I38400, ["ENCODERS CLEARED", CR]
   PAUSE 250
   
MAIN
   IF CLEARPB = 0 THEN CLEARENC
   IF RUNPB <> 0 THEN MAIN
   
'   READ AND DISPLAY CURRENT POSITION, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 17
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1DIST.BYTE3, R1DIST.BYTE2, R1DIST.BYTE1, R1DIST.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["POSITION ", DEC R1DIST, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1DIST.BYTE3 + R1DIST.BYTE2 + R1DIST.BYTE1 |
          + R1DIST.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR, CR]
   PAUSE 10

'   DRIVE M1 FORWARD SIGNED SPEED AND DISTANCE AND ACCELERATION
   R1COMMAND = 45
   R1SPEED = 48000
   R1DIST = 96000
   R1ACCEL = 48000
   R1BUFFER = 0
   R1CRC = (R1ADDRESS + R1COMMAND + |
          R1ACCEL.BYTE3 + R1ACCEL.BYTE2 + R1ACCEL.BYTE1 + R1ACCEL.BYTE0 + |
          R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 + R1SPEED.BYTE0 + |
          R1DIST.BYTE3 + R1DIST.BYTE2 + R1DIST.BYTE1 + R1DIST.BYTE0 + |
          R1BUFFER) & 0x7f
   HSEROUT [R1ADDRESS, R1COMMAND, |
          R1ACCEL.BYTE3, R1ACCEL.BYTE2, R1ACCEL.BYTE1, R1ACCEL.BYTE0, |
          R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, R1SPEED.BYTE0, |
          R1DIST.BYTE3, R1DIST.BYTE2, R1DIST.BYTE1, R1DIST.BYTE0, |
          R1BUFFER, R1CRC]
   PAUSE 1000

LOOPER
'   READ AND DISPLAY CURRENT SPEED, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 19
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1SPEED.BYTE3, R1SPEED.BYTE2, R1SPEED.BYTE1, R1SPEED.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["SPEED    ", DEC R1SPEED, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1SPEED.BYTE3 + R1SPEED.BYTE2 + R1SPEED.BYTE1 |
          + R1SPEED.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR, CR]
   PAUSE 250

'   WAIT FOR MOTOR TO STOP
   IF R1SPEED <> 0 THEN LOOPER

'   READ AND DISPLAY CURRENT POSITION, VERIFY GOOD READ BY COMPARING CHECKSUMS
   R1COMMAND = 17
   HSEROUT [R1ADDRESS, R1COMMAND]
   HSERIN [R1DIST.BYTE3, R1DIST.BYTE2, R1DIST.BYTE1, R1DIST.BYTE0, R1STATUS, R1CRC]
   SEROUT S_OUT, I38400, ["POSITION ", DEC R1DIST, CR]
   SEROUT S_OUT, I38400, ["STATUS   ", DEC R1STATUS, CR]
   SEROUT S_OUT, I38400, ["CHECKSUM ", DEC R1CRC, CR]
   R1CRC = (R1ADDRESS + R1COMMAND + R1DIST.BYTE3 + R1DIST.BYTE2 + R1DIST.BYTE1 |
          + R1DIST.BYTE0 + R1STATUS) & 0x7F
   SEROUT S_OUT, I38400, ["CRC CALC  ", DEC R1CRC, CR, CR]
   PAUSE 100   
GOTO MAIN

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Tue Oct 04, 2011 11:31 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
The random bad characters could be noise from your motors maybe? :)

Also constants don't support the .byte# modifiers. To break a constant into byte sized peices use right shifts(>>) something like this:

mycon con 0x12345678
hserout [mycon>>24,mycon>>16,mycon>>8,mycon]

The compiler, when it can figure it out will process the constant expressions at compiletime instead of wasting code space but the draw back is it means the varibale modifiers don't work on constants(eg why they are called variable modifiers :) ).

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Reading Quadrature Encoder with Roboclaw 2x5A
PostPosted: Wed Oct 05, 2011 6:49 am 
Offline
Guru

Joined: Mon Apr 19, 2010 9:13 am
Posts: 63
Thanks for the tip. In attempt to save ram, (and because I didn't actually need such high values) I reduced several of the roboclaw variables to words. I replaced all .byte3 and .byte2 values with 0s.

_________________
Studio 2.0.0.16 on Win 7 Home x64 updated daily - Original Roboclaw 5A V1.3.9
Mostly a Nano40 for prototyping, but I have others in my bins


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO