SDC2130 - Read encoder using CAN
6 years 3 months ago #29532723
by metRo_
SDC2130 - Read encoder using CAN was created 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.
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.
6 years 3 months ago #29532725
by blake
Replied by blake on topic SDC2130 - Read encoder using CAN
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.
6 years 3 months ago #29532728
by metRo_
Replied by metRo_ on topic SDC2130 - Read encoder using CAN
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.
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.
6 years 3 months ago #29532736
by blake
Replied by blake on topic SDC2130 - Read encoder using CAN
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
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.
6 years 2 months ago - 6 years 2 months ago #29532759
by metRo_
Replied by metRo_ on topic SDC2130 - Read encoder using CAN
Please Log in or Create an account to join the conversation.
6 years 2 months ago #29532778
by metRo_
Replied by metRo_ on topic SDC2130 - Read encoder using CAN
Any update on it?
Please Log in or Create an account to join the conversation.
6 years 2 months ago #29532779
by blake
Replied by blake on topic SDC2130 - Read encoder using CAN
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.
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.
6 years 2 months ago #29532793
by metRo_
Replied by metRo_ on topic SDC2130 - Read encoder using CAN
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.
5 years 11 months ago #29532964
by Rorence
Replied by Rorence on topic SDC2130 - Read encoder using CAN
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.086 seconds