Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked
Resolved Resolved by DJ Sures!

Cycle Servos For Controller Analog Sticks

I'm looking to use my L2 and R2 buttons to change what servo groups my analog sticks control when they are held, is there a way to do this?

The current method I found is to use third party software to map the joystick directions to keys, then use the keyboard skill. I have the L2 and R2 set variables when they are down and then the joystick mapped keys run the scripts for the correct servo set depending on if the variable is set.

However I'm finding this method has a noticeable lag from the L2 button being pressed and the variable being switched. The keyboard skill shows the button press instantly but the set variables delayed.

Thanks


Related Hardware Arduino Due/Mega

ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a cool new tool that will help unleash your creativity with programming robots in just seconds!

PRO
Synthiam
#1   — Edited
You should never need a third-party program - plus, most third-party stuff never works.:)

If this isn't the joystick skill you're using, you should use it: https://synthiam.com/Support/Skills/Navigation/Joystick-XInput?id=19182.

The only thing is there is no "Servo group." Unless you're modifying the code on the Arduino to switch servo mapping with those buttons.

That does remind me of maybe a mapping skill. It might be helpful to have a skill that maps Vx servos to anything else, as in groups. Perhaps I'll create one for you. 

In the meantime, you'd have to create a script skill that does it for you...

An init script (on connection) initializes the $JoyServoGroup variable. Put this in the connection control or your init script

Code:



// Set the default servo group to 0
setVar("$JoyServoGroup", 0);

// Start the servo group mapping script
ControlCommand("ServoGroups", "ScriptStart");



Create a script called "ServoGroups". This will map the Vx servos to Dx servos for you

Code:


while (true) {

if (getVar("$JoyServoGroup") == 0) {

// map V0 to D0
Servo.setPosition(d0, Servo.getPosition(v0));

// map V1 to D1
Servo.setPosition(d1, Servo.getPosition(v1));

// map V2 to D2
Servo.setPosition(d2, Servo.getPosition(v2));

// map V3 to D3
Servo.setPosition(d3, Servo.getPosition(v3));

} else if (getVar("$JoyServoGroup") == 1) {

// map V0 to D5
Servo.setPosition(d5, Servo.getPosition(v0));

// map V1 to D6
Servo.setPosition(d6, Servo.getPosition(v1));

// map V2 to D7
Servo.setPosition(d7, Servo.getPosition(v2));

// map V3 to D8
Servo.setPosition(d8, Servo.getPosition(v3));
}

// Set this for your cpu usage and servo smoothness.
// If the sleep is too small, it'll use more cpu and bandwidth
sleep(250);
}


And finally, in the Joystick Robot Skill, use the Vx servos as referenced in the above script.
User-inserted image


User-inserted image



And finally, set buttons to move the servo groups. I don't have a joystick with me so i don't know what buttons 16 and 17 are. But you can change to what ever...
User-inserted image


Here's a demo project: Example - Joystick servo Group.EZB
#3  
Ok thanks I'm getting somewhere now.

Part of the issue was that I forgot L2 and R2 are analog buttons.

L1 and R1 are better suited to use which are 10 and 11 on the joysticks skill.

I'm testing your method which is what I was after. 

However I'm still seeing a lag on the $joyservogroup variable switching on button press. 
On the the Joystick(Xinput) skill window i see the press register instantly, however in the variable watch window and also the robot switching between servo groups its about a 2 second delay.  Is this normal?
Is seems odd that ARC sees the button press but takes so long to switch the variable.
PRO
Synthiam
#4  
The variable watch has a delay when updating. But the variable would be updated immediately. There is no delay when updating a variable. When the variable is assigned a new value, it’s immediately set with that value. 

How’s your CPU usage during the project? Are you lagging the cpu with something?
#5   — Edited
Checked CPU and its at 15%

No idea why but when I ditched servo Script and created my own it all seems to function now, nice and fast.

Thanks Again DJ

I used your method as follows,
used L1 to set $L1_Pressed
when $L1_Pressed = 0    mapped the V2 to V12
then used the following script

Code:

while (true) {

if ((Servo.GetPosition(v12, 0)) == 180) {

controlCommand("Script Collection", "ScriptStart", "Dome Left Con");


}

if ((Servo.GetPosition(v12, 0)) == 1) {

controlCommand("Script Collection", "ScriptStart", "Dome Right Con");


}
if (getVar("$L1_Pressed") == 0 && (Servo.GetPosition(v12, 0)) == 90) {

controlCommand("Script Collection", "ScriptStart", "Stop Dome");


}

sleep(200);


}
This moves the dome with the Right stick.


when $L1_Pressed = 1
maps V0 through V3 to the Arm Servos allowing me to used the sticks to control the arms, Dome Movement moves over to the D-pad. 
So Simple a 9 year old can work it:)
PRO
Synthiam
#6  
Haha that’s such a great video!! Gonna be a pretty wild robot. Glad you shared it
PRO
USA
#8  
great going Davidaharrison

EzAng
#9  
Ok not sure what happened but I'm not seeing the virtual servo V12 which is mapped from V2 go to 90 degrees at center.

This seemed to work before yesterday I noticed that it seemed to be going to 180 on a full right then returning to 1.

I did an ARC update, been a few months since my last, not sure if this is related.

Its been a while since I had to look at mapping from the joystick but I believe they were always 90 on center?
#11  
Ok no worries,

I just redid it using JoystickX2 Variables, no idea why I did not do that the first time round, its funny going back sometimes over old work.