SDC2130 - Read encoder using CAN

3 years 8 months ago #29532723 by metRo_
I'm using the AN1543 as a base for connecting two roboteq using CAN. I'm getting problems reading the encoder values from the slave.
As you can see, each 10 seconds I got wrong values for encoder, it looks like it send the double of the real value.



option explicit
' Mecanum drive demonstrator
' Script is written for use in SDC2130 but will work on any other model by changing where commented.
' Script must be loaded and executed in controller that will serve as Master on a RoboCAN network.
' Second dual channel controller will act a Slave. Master node id=1, Slave node id=2
' Script is provided for demonstration purposes, as-is without warranty.
 
dim VD as integer ' Desired Robot Speed
dim ThetaD as integer ' Desired Angle
dim VTheta as integer ' Desired Rotation Speed
dim ThetaD45 as integer ' Desire Angle + 45o
 
' Previous values for change detection
dim PrevVD as integer ' Desired Robot Speed
dim PrevThetaD as integer ' Desired Angle
dim PrevVTheta as integer ' Desired Rotation Speed
 
dim V1 as integer ' Front Left motor
dim V2 as integer ' Front Right motor
dim V3 as integer ' Rear Left motor
dim V4 as integer ' Rear Right motor
 
dim c1 as integer
dim c2 as integer
dim c3 as integer
dim c4 as integer
 
dim cWait as integer
 
dim LR as integer ' Left/Right Command
dim FR as integer ' Forward/Reverse Command
dim CCW as integer ' Rotation command
 
dim RadioVD as integer ' VD from joystick
dim RadioTh as integer ' Theta from joystick
 
dim CANAlive as integer ' Alive Robocan nodes
 
dim c21 as boolean
dim c22 as boolean
dim c2send as boolean
 
ScanCANValue(2,_C,1,21,0)
ScanCANValue(2,_C,2,21,1)
 
c21 = false
c22 = false
c2send = false
cWait = 0
 
Top:
    ' Use code below to accept commands via RS232 or USB
    ' Send commands with !VAR nn value
    ' VAR 1 contains motion speed, +/-1000 range
    ' VAR 2 contains motion direction, 0-360 degree range
    ' VAR 3 contains rotation speed, +/-1000 range
    VD = getvalue(_VAR, 1)
    ThetaD = getvalue(_VAR, 2)
    VTheta = getvalue(_VAR, 3)
     
    ' Read list of alive RoboCAN nodes
    CANAlive = getvalue(_CL, 1)
     
    ' Check if Slave is present
    if(CANAlive <> 273)
             V1 = 0
             V2 = 0
             V3 = 0
             V4 = 0
             goto ApplyCommand ' Stop all motors if no radio or no slave
    end if
     
    ' To avoid unnecessary computation, evaluate formulas only if change occurred
    if (VD <> PrevVD or ThetaD <> PrevThetaD or VTheta <> PrevVTheta)
     
             ThetaD45 = ThetaD + 45 ' compute once angle + 45 for use in the 4 equations
           
             V1 = (VD * sin(ThetaD45))/1000 + VTheta ' sin takes degrees and returns result * 1000
             V2 = (VD * cos(ThetaD45))/1000 - VTheta
             V3 = (VD * cos(ThetaD45))/1000 + VTheta
             V4 = (VD * sin(ThetaD45))/1000 - VTheta
           
             ' Uncomment below to view computed speeds in console
             'print (V1,"\t",V2,"\t",V3,"\t",V4,"\r")
    end if
     
    ' Save for detecting change at next loop execution
    PrevVD = VD
    PrevThetaD = ThetaD
    PrevVTheta = VTheta
 
    if(IsScannedCANReady(0))
       c3 = ReadScannedCANValue(0)
       c21 = true
    end if
   
    if(IsScannedCANReady(1))
       c4 = ReadScannedCANValue(1)
       c22 = true
    end if
   
    if(c21 = true and c22 = true)
        c1 = getValue(_C,1)
        c2 = getValue(_C,2)
        print("&f:")
        print(c1,":")
        print(c2,":")
        print(c3,":")
        print(c4,"\r")
    end if
 
ApplyCommand:
    ' Apply to local motors
    SetCommand(_G, 1, V1)
    SetCommand(_G, 2, V2)
    ' Send command to Slave, node 2 on RoboCAN network
    SetCANCommand(2, _G, 1, V3)
    SetCANCommand(2, _G, 2, V4)
   
wait(20) ' Repeat loop every 10ms / 100Hz
 
goto top

Please Log in or Create an account to join the conversation.

3 years 8 months ago #29532725 by blake
If you connect the slave controller directly to Roborun+ do you observe the same behavior from the encoder?

Please Log in or Create an account to join the conversation.

3 years 8 months ago #29532728 by metRo_
I think It is a problem with CAN. I changed the master/slave and the problem moves to the new slave.

By reading the encoder with Roborun+ the values are ok. I connect both roboteq to pc and it works ok too.

If I change the time on ScanCANValue the error occurs at different frequency.

Please Log in or Create an account to join the conversation.

3 years 8 months ago #29532736 by blake
Hello

We are investigating this but need a bit more information. Please send me the following:

1. Your controllers configuration file (will need to put in .zip format to attach to a forum post)

2. Send the query ?FID from the console tab of Roborun+ and tell me what the response is.

3. Send the query ?UID from the console tab of Roborun+ and tell me what the response is.

Thanks

Please Log in or Create an account to join the conversation.

3 years 8 months ago - 3 years 8 months ago #29532759 by metRo_
FID=Roboteq v1.6 SDC2XXX 04/14/2016
UID=300:1058:3538989:1379096326:540424249

We tried to update firmware without success. Popup says it successfully update the firmware but if you look at the log you can see it failed to wait for roboteq to restart.
Attachments:

Please Log in or Create an account to join the conversation.

3 years 7 months ago #29532778 by metRo_
Any update on it?

Please Log in or Create an account to join the conversation.

3 years 7 months ago #29532779 by blake
Hello, sorry I had missed your last message somehow.

Generally the controller should reset itself automatically when it gets to the step "Waiting for Device to Restart." If it does not restart itself then you will simply need to turn off power to the controller and then turn it back on again at this step.

First, ensure that you are using the correct method to update the controllers firmware. If your controller is connected to your PC via RS232 (even USB - RS232 adapter) then you need to use the "Update Controller via COM" option. If the controller is connected to the computer via strait USB, then you will use the "Update Controller via USB" option.

Please Log in or Create an account to join the conversation.

3 years 7 months ago #29532793 by metRo_
I'll try to update it. About the can error have you tried anything?

Please Log in or Create an account to join the conversation.

3 years 5 months ago #29532964 by Rorence
Teach us more in this field. After reading on here, we can learn more in this topic.

Please Log in or Create an account to join the conversation.

Moderators: tonysantoni
Time to create page: 0.365 seconds