ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

PRO
Synthiam
#9  

If you need to sequence the calibration, maybe do that programmatically rather than automatically in the firmware. You can trigger each Calibrate option using the ControlCommand() spaced out from each other.

@Athena do you have any suggestions about my idea? Provide as much information as you have on this topic and be detailed.

PRO
Canada
#10  

To sequence the calibration of multiple stepper motors programmatically, you can use the ControlCommand() function in ARC to send calibration commands to each stepper motor individually. By adding delays between each command, you can ensure that the calibration process is carried out one motor at a time, reducing the risk of collisions or other issues.

Here's a detailed approach to achieve this:

  1. Identify the Virtual servo Ports: Determine the Virtual servo Ports (e.g., V21, V22, etc.) that correspond to each stepper motor you want to calibrate.

  2. Create a Calibration Script: Write a script in ARC that sends the Calibrate ControlCommand to each stepper motor in sequence. Include a delay between each command to allow time for each motor to complete its calibration before the next one starts.

  3. Use Delays: Utilize the sleep() function in JavaScript to introduce pauses between calibration commands. This ensures that each stepper motor has enough time to reach its limit switch and set its home position before the next motor begins its calibration.

  4. Execute the Script: Run the script as part of your robot's initialization routine or manually when you need to recalibrate the stepper motors.

Here's an example of how you might write such a script in JavaScript within ARC:

// Calibrate stepper motor connected to V21
ControlCommand("Stepper Servo", "Calibrate", "V21");
// Wait for the calibration to complete before moving to the next motor
sleep(5000); // Delay for 5 seconds (adjust time as needed)

// Calibrate stepper motor connected to V22
ControlCommand("Stepper Servo", "Calibrate", "V22");
// Wait for the calibration to complete before moving to the next motor
sleep(5000); // Delay for 5 seconds (adjust time as needed)

// Add additional calibration commands and delays for more stepper motors as needed

Replace "Stepper Servo" with the actual name of your Stepper servo robot skill, and adjust the Virtual servo Port names (V21, V22, etc.) and delay times as necessary for your specific setup.

By following this approach, you can ensure a safe and controlled calibration process for each stepper motor in your robot. Remember to test the script in a safe environment to fine-tune the delay times and ensure that the calibration sequence works as expected.


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.
#11  

@Athena Is it possible to set a stepper V21 position to 12833 when it is triggered by an ADC 3 switch? How do you write the Javascript code for ARC to do this? This would give me different options for simulating calibrating and zeroing an axis. If I know the exact position of a switch that is near the middle of a rack gear it would do the same thing as zeroing it. I may want to put a limit switch on each end of travel and switch in the middle to give me more options. Can you write the Javascript code for having a lower limit switch, a higher limit switch, and midrange switch that I can provide the value if it is triggered. There is no need to do any more calibrating when any one of these three switches because it will reset the value in ARC and in the Arduino.

PRO
Canada
#12  

Certainly! To set a stepper motor's position based on an ADC switch trigger, you can use JavaScript in ARC to monitor the ADC value and then issue a command to move the stepper motor to a specific position when the switch is activated. Below is an example of how you might write the JavaScript code to achieve this:

// Function to check the ADC value and set stepper position
function checkAdcAndSetStepper() {
  // Read the value from ADC port 3
  var adcValue = ADC.get(3);

  // Define the threshold value to determine if the switch is triggered
  var threshold = 100; // Adjust this value based on your switch trigger level

  // Check if the ADC value is above the threshold (switch is triggered)
  if (adcValue > threshold) {
    // Set the stepper motor connected to V21 to position 12833
    Servo.setPosition(V21, 12833);
  }
}

// Call the function to check ADC and set stepper position
checkAdcAndSetStepper();

For the scenario with multiple limit switches (lower, higher, and midrange), you can expand the code to include additional checks for each switch and set the stepper position accordingly. Here's an example:

// Function to check ADC values for multiple switches and set stepper position
function checkAdcAndSetStepperWithLimits() {
  // Read the values from ADC ports for each switch
  var lowerSwitchValue = ADC.get(1); // ADC port for lower limit switch
  var higherSwitchValue = ADC.get(2); // ADC port for higher limit switch
  var midrangeSwitchValue = ADC.get(3); // ADC port for midrange switch

  // Define the threshold value for switch activation
  var threshold = 100; // Adjust this value based on your switch trigger level

  // Check if the lower limit switch is triggered
  if (lowerSwitchValue > threshold) {
    // Set the stepper motor connected to V21 to the lower limit position
    Servo.setPosition(V21, 0); // Assuming 0 is the lower limit position
  }

  // Check if the higher limit switch is triggered
  if (higherSwitchValue > threshold) {
    // Set the stepper motor connected to V21 to the higher limit position
    Servo.setPosition(V21, 25500); // Assuming 25500 is the higher limit position
  }

  // Check if the midrange switch is triggered
  if (midrangeSwitchValue > threshold) {
    // Set the stepper motor connected to V21 to the midrange position
    Servo.setPosition(V21, 12833); // The provided midrange position
  }
}

// Call the function to check ADC and set stepper position with limits
checkAdcAndSetStepperWithLimits();

In this code, you'll need to adjust the threshold value to match the level at which your switches trigger. You'll also need to set the correct positions for the lower and higher limits based on your stepper motor's range.

Remember to replace V21 with the actual Virtual servo Port that corresponds to your stepper motor, and adjust the ADC port numbers (1, 2, 3) to match the ports where your switches are connected.

This script should be run in a loop or on a timer if you want to continuously monitor the ADC values and respond to switch triggers. You can use ARC's built-in timing functions to execute the checkAdcAndSetStepperWithLimits() function at regular intervals.


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.
#13  

@Athena that was a very good answer and it should be very helpful! Thanks.

PRO
Canada
#14  

You're welcome! If you have any more questions or need further assistance with your project, feel free to ask. Good luck with your robot, and happy building!


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.
#15  

@Athena continuing on the same conversation, unfortunately Servo.setPosition(V21, 12833); did not work. It physically moves the servo to that position, wheres it was supposed to set the position without it moving. Is the Stepper servo skill set up to handle this type of script? Do you have any other suggestions?

PRO
Canada
#16  

I apologize for the confusion. The Servo.setPosition() command in ARC is indeed used to command the servo to move to a specified position. If you want to set the position of the stepper motor without physically moving it, you would typically use a calibration or homing procedure.

However, based on your requirements, it seems you want to redefine the stepper's current position as a specific value without moving it. This functionality is not standard in most servo control systems, as they usually only track relative movement from a known home position.

If the Stepper servo skill does not natively support setting a position without moving, you would need to modify the Arduino firmware to include a custom command that allows you to redefine the current position. This would involve programming a specific command that the Arduino firmware can recognize and execute to update its internal position counter without physically moving the stepper motor.

Here's a conceptual example of how you might implement this in the Arduino firmware:

// Custom command to set the current position without moving
if (command == "SETPOS") {
  long newPosition = getLongFromSerial();
  setCurrentPosition(newPosition);
}

And the corresponding JavaScript code in ARC to send this custom command to the Arduino:

// Function to send a custom command to set the stepper position without moving
function setStepperPositionWithoutMoving(virtualPort, position) {
  // Replace with the actual COM port and baud rate used by your Arduino
  var comPort = "COMx";
  var baudRate = 9600;
  
  // Open the COM port
  COM.open(comPort, baudRate);
  
  // Send the custom command followed by the position
  // The command format would depend on how you implement it in the Arduino firmware
  COM.writeString(comPort, "SETPOS " + position + "\n");
  
  // Close the COM port
  COM.close(comPort);
}

// Example usage: Set the position of stepper motor on virtual port V21 to 12833 without moving
setStepperPositionWithoutMoving("V21", 12833);

Please note that this is a conceptual example and would require you to implement the setCurrentPosition() function and the getLongFromSerial() parsing function in your Arduino firmware. The actual implementation would depend on the specifics of your firmware and how you handle serial commands.

If you're not comfortable modifying the Arduino firmware, another approach would be to create a custom robot skill in ARC that includes this functionality. You can learn more about creating custom robot skills in the ARC documentation: Create Robot Skill.

Before proceeding with firmware modifications or custom skill creation, I recommend reaching out to the developer of the Stepper servo skill or consulting the skill's documentation to see if there's an existing feature or command that meets your needs.


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.