Menu

Topic-icon Mix mode 3 mimic script

More
2 years 11 months ago #29532598 by robrc12
Hi dose anyone have a script that mimics mix mode 3 ?

I am currently using this script but lack the control needed that mix mode 3 provided when I was using a single controller.

Thanks
Rob

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 MotorSpeedLeft as integer ' JoystickYont Left motor
dim MotorSpeedRight as integer ' JoystickYont Right motor
dim JoystickX as integer ' Left/Right Command
dim JoystickY as integer ' Forward/Reverse Command

dim CANAlive as integer ' Alive Robocan nodes

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 JoystickYom standard RC Radio
JoystickX = getvalue(_AIC, 1) ' X of X-Y joystick
JoystickY = getvalue(_AIC, 2)

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

' Check if Slave is present
if (CANAlive <> 273)
MotorSpeedLeft = 0
MotorSpeedRight = 0
print ("Slave detection failed ... shutting down.\r")
goto ApplyCommand ' Stop all motors if no radio or no slave
end if
print (" JoystickX=", JoystickX, " JoystickY=", JoystickY, ".\r")

MotorSpeedLeft = JoystickY
MotorSpeedRight = JoystickY
MotorSpeedLeft -= JoystickX
MotorSpeedRight += JoystickX
if (MotorSpeedLeft > 1000) then MotorSpeedLeft = 1000
if (MotorSpeedLeft < -1000) then MotorSpeedLeft = -1000
if (MotorSpeedRight > 1000) then MotorSpeedRight = 1000
if (MotorSpeedRight < -1000) then MotorSpeedRight = -1000

ApplyCommand:
' Apply to local motors
SetCommand(_G, 1, MotorSpeedRight)
' Send command to Slave, node 2 on RoboCAN network
SetCANCommand(2, _G, 1, MotorSpeedLeft)

wait(10) ' Repeat loop every 10ms / 100Hz

goto top

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

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