Menu

Topic-icon CAN and RC_Omnidirectional Robots

More
3 years 5 months ago #29532108 by Richard_Tecdron
Hello,
I set up a link for RC pilot a robot "Driving Wheels Mecanum Omnidirectional Robot" (see listing).
I do not know the settings to make in the script model you give an example:
I use 2 SDC2130 controllers (update V1.6) connect CAN, RC1 and RC2 of the "master" are connected to RC receiver

My RC remote control I have 2 joysticks 2 axis and 3-axis joystick 1
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)
' Capture joystick value
' Code below is for use on SDC21300 with Specktrum Radio enabled.
' Change to _PI to capture from standard RC Radio
LR = getvalue(_K, 2) ' X of X-Y joystick
FR = getvalue(_K, 3)
CCW = getvalue(_K, 4)
' Read list of alive RoboCAN nodes
CANAlive = getvalue(_CL, 1)
' Check if Radio is on and Slave is present
if(LR = 0 or FR = 0 or CCW = 0 or CANAlive <> 273)
V1 = 0
V2 = 0
V3 = 0
V4 = 0
goto ApplyCommand ' Stop all motors if no radio or no slave
end if

Can you explain to me the settings to perform.

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

More
3 years 5 months ago #29532109 by blake
The code sample you referenced is by default scripted for a Spektrum Radio Receiver. If you are using a standard RC receiver then all you need to do is change the _K in the script to _PI. Each joystick axis will correspond to one of the Pulse inputs so you can adjust the script based on which pulse input you use. See below:

' Capture joystick value
' Code below is for use on SDC21300 with Specktrum Radio enabled.
' Change to _PI to capture from standard RC Radio
LR = getvalue(_PI, 2) 'Pulse input 2
FR = getvalue(_PI, 3) 'pulse input 3
CCW = getvalue(_PI, 4)'Pulse input 4
' Read list of alive RoboCAN nodes
CANAlive = getvalue(_CL, 1)
' Check if Radio is on and Slave is present
if(LR = 0 or FR = 0 or CCW = 0 or CANAlive <> 273)
V1 = 0
V2 = 0
V3 = 0
V4 = 0
goto ApplyCommand ' Stop all motors if no radio or no slave
end if

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

More
3 years 5 months ago #29532110 by blake
I need to correct my previous comment. _K needs to be change to _PIC not _PI. This will allow the pulse input to be scaled correctly to become the corresponding +/-1000 command. Se corrected script below:

' Capture joystick value
' Code below is for use on SDC21300 with Specktrum Radio enabled.
' Change to _PIC to capture from standard RC Radio
LR = getvalue(_PIC, 2) 'Pulse input 2
FR = getvalue(_PIC, 3) 'pulse input 3
CCW = getvalue(_PIC, 4)'Pulse input 4
' Read list of alive RoboCAN nodes
CANAlive = getvalue(_CL, 1)
' Check if Radio is on and Slave is present
if(LR = 0 or FR = 0 or CCW = 0 or CANAlive <> 273)
V1 = 0
V2 = 0
V3 = 0
V4 = 0
goto ApplyCommand ' Stop all motors if no radio or no slave
end if

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

More
3 years 5 months ago #29532113 by Richard_Tecdron
Hello,
Thank you for the code.
Here is your code:

Capture joystick value
' Code below is for use on SDC21300 with Specktrum Radio enabled.
' Change to _PI to capture from standard RC Radio
' X of X-Y joystick
LR = getvalue(_PI, 3)
FR = getvalue(_PI, 2)
CCW = getvalue(_PI, 1)

' Read list of alive RoboCAN nodes
CANAlive = getvalue(_CL, 1)

' Check if Radio is on and Slave is present
if(LR = 0 or FR = 0 or CCW = 0 or CANAlive <> 273)
V1 = 0
V2 = 0
V3 = 0
V4 = 0
goto ApplyCommand ' Stop all motors if no radio or no slave
end if

' Centered joystick = 1500. Substract offset to convert to 0 to +/-1000
' Change code below to adapt to other radio than spektrum
if LR < 1500
LR = (LR - 1500) * 2 ' Multipy by 2 to bring closer to +/-1000
if LR > 0 then LR = 0
elseif LR > 1530
LR = (LR - 1530) * 2
if LR < 0 then LR = 0
else
LR = 0
end if
LR = -LR

if FR < 1500
FR = (FR - 1500) * 2
if FR > 0 then FR = 0
elseif FR > 1530
FR = (FR - 1530) * 2
if FR < 0 then FR = 0
else
FR = 0
end if
FR = -FR

if CCW < 1500
CCW = (CCW - 1500) * 2
if CCW > 0 then CCW = 0
elseif CCW > 1530
CCW = (CCW - 1530) * 2
if CCW < 0 then CCW = 0
else
CCW = 0
end if

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

  • roboteq
  • roboteq's Avatar
3 years 5 months ago #29532114 by roboteq
Replied by roboteq on topic CAN and RC_Omnidirectional Robots
You really should use the _PIC and not _PI

In your code you are doing the conversion of pulse widths in microseconds to a +/- 1000 command.

The PIC gives you the same without the effort. In addition is uses the min/max/center/deadband info. So you get more flexibility and accuracy.

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

Moderators: tonysantoni
Time to create page: 0.087 seconds
Go to top