Asked

Making Motion Arrive At The Same Time

Is there a certain command/parameter that I need to put in Javascript and if possible in Blockly to move axes with different values arrive at the same time? Example: Move servo V1 to 5565 and Move V21 to 8755 at the same time and then arrive at the same time. I know it can be done with Auto Position but I'd like it in Javascript so that I can substitute with a variable and then just keep changing the variable as needed.    On a different note is there any way to make servo positions in Auto Position be a variable? This seems like it would be very useful?


Related Hardware EZ-B v4
Related Controls Script Auto Position (Gait)

ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

PRO
Canada
#1  

To achieve synchronized servo movements in JavaScript within ARC, where servos with different target positions arrive at their destinations simultaneously, you can utilize the concept of proportional speed adjustment based on the distance each servo needs to travel. Unfortunately, direct support for setting servo speeds individually in JavaScript or Blockly within ARC to ensure simultaneous arrival isn't straightforward due to the scripting environment's limitations. However, you can approximate this behavior by calculating the duration each movement should take based on the furthest distance to travel and setting a delay for the movements accordingly.

Here's a conceptual approach in JavaScript for ARC:

// Define the start and end positions for each servo
var startPosV1 = getCurrentPosition("V1");
var endPosV1 = 5565;
var startPosV21 = getCurrentPosition("V21");
var endPosV21 = 8755;

// Calculate the distance each servo needs to travel
var distanceV1 = Math.abs(endPosV1 - startPosV1);
var distanceV21 = Math.abs(endPosV21 - startPosV21);

// Determine the maximum distance to travel
var maxDistance = Math.max(distanceV1, distanceV21);

// Assuming a constant speed, calculate the time needed for the furthest movement
var totalTime = calculateTime(maxDistance);

// Move each servo, adjusting the speed so they arrive simultaneously
moveServoWithTime("V1", endPosV1, totalTime);
moveServoWithTime("V21", endPosV21, totalTime);

// Function to move a servo to a position over a specified time
function moveServoWithTime(port, position, time) {
    // You would need to implement this function based on your robot's capabilities
    // This might involve setting the servo speed based on the distance and total time
}

// Function to calculate the time needed for the furthest movement
function calculateTime(distance) {
    // Implement your logic to calculate time based on distance
    // This could be a simple proportional calculation or based on experimentation
    return time;
}

This script is conceptual and requires you to fill in the implementation details, such as how to get the current position of a servo (getCurrentPosition), how to move a servo over a specified time (moveServoWithTime), and how to calculate the time needed for the movement (calculateTime). These functions depend on your robot's specific capabilities and the APIs provided by ARC for JavaScript.

Regarding making servo positions in Auto Position be a variable, ARC's Auto Position skill does not directly support using variables for frame positions through the GUI. However, you can dynamically adjust servo positions by using scripts to modify the positions before executing an action. You would use the ControlCommand to set servo positions programmatically before calling the action that uses those positions. This approach requires a combination of scripting and creative use of the Auto Position skill to achieve dynamic behavior based on variables.

For Blockly, achieving synchronized servo movements with variable positions would follow a similar conceptual approach, but Blockly's capabilities for complex mathematical calculations and dynamic control are more limited compared to JavaScript. You might need to rely more on predefined movements and scripts for complex behaviors.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#2   — Edited

@Athena  This is a pretty interesting approach doing it with time and it makes sense. One thing that I did notice when setting speed variables for steppers on my metal cutting lathe is that a speed setting of 19 was still too fast and a speed setting of 20 was too slow. I ended up writing my own script to modify the speed exactly how I wanted it. Is there an area in Javascript code that I can modify the mapping of the speed?  I also would like to verify that the mapping is linear and not exponential.

#4  

Yup, you're right. I managed  to use the Auto Position and a separate script to make it work the way I wanted. Thanks