Asked
Resolved Resolved by DJ Sures!

Movement Panel With Servo Control

I have modified my 3-wheel robot by replacing the two 360-degree servos with a motor equipped with a differential. This motor is controlled by a dual H-bridge using PWM signals. While I'm not entirely sure if this is the optimal setup, I'm still learning and experimenting with various possibilities. Currently, the single motor controls both rear wheels, allowing for synchronized forward and reverse movement, which is functioning well.

For steering, I have installed a servo at the front to control the wheel's left-right movement. However, I'm encountering an issue where the joystick correctly manages the forward and reverse motion but fails to control the steering. I would like to have a single control interface or "tool" that can manage both forward/reverse and left/right steering using the servo. If achieving this with a joystick is not feasible, could you suggest an alternative solution?


Related Hardware AdventureBot
Related Control Custom Movement Panel

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
Germany
#17  

@athena i got an error with the following script:

// Assuming speedDifference is calculated from joystick input var speedDifference = getVar("$SpeedDifference"); // Replace with actual calculation var steeringAngle = Utility.map(speedDifference, -255, 255, 40, 170); // Map speed difference to servo angles Servo.setPosition("D4", steeringAngle); // Adjust the port as needed

Start Execution Error Line 4 Col 0 - Variable not defined: $SpeedDifference Done (00:00:00.0077419) I thought a syntax error with speedDifference or SpeedDifference but it is the same

PRO
Canada
#18  

The error message indicates that the variable $SpeedDifference is not defined in your script. This variable needs to be calculated or set before you use it in the Utility.map() function. Here's how you can address this issue:

Steps to Fix the Error

  1. Define the Variable:

    • Ensure that $SpeedDifference is calculated based on your joystick input. This variable should represent the difference in speed between the left and right directions of the joystick.
  2. Example Calculation:

    • If you're using a joystick, you might calculate the speed difference based on the X-axis input. Here's an example of how you might define it:
// Example: Calculate speed difference from joystick input
var joystickX = getVar("$JoystickX"); // Replace with actual joystick X-axis variable
var speedDifference = joystickX - 128; // Assuming joystick center is 128
  1. Update Your Script:
    • Incorporate the calculation into your script before using it in the Utility.map() function.
// Calculate speed difference from joystick input
var joystickX = getVar("$JoystickX"); // Replace with actual joystick X-axis variable
var speedDifference = joystickX - 128; // Assuming joystick center is 128

// Map speed difference to servo angles
var steeringAngle = Utility.map(speedDifference, -255, 255, 40, 170); // Adjust range as needed
Servo.setPosition(D4, steeringAngle); // Adjust the port as needed

Additional Tips

  • Check Joystick Variables:

    • Ensure that the joystick input variables are correctly defined and updated in your project. You might need to check the joystick control settings to find the correct variable names.
  • Test and Adjust:

    • Test the script and adjust the mapping range in Utility.map() to suit your robot's steering requirements.

If you have any more questions or need further assistance, feel free to ask!


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.
PRO
Synthiam
#19   — Edited

Please use the scripts that I posted because it works, and was tested. The code Athena is posting is confusing because it’s about trying to turn and stuff - and us getting confused. The main topic of conversation we should stick to has been addressed in my scripts.

adjust the map values as needed for steering range and movement speed.

PRO
Germany
#20  

ok i go back to your scripts.

PRO
Synthiam
#21  

They will work great if you modify the range values for the steering and speed. Also remove the additional digital port if youre only using one wire.

as for the stop, simply specify the pwm to have a value of 0.

let me know your experience. The left and right scripts won’t work as the robot can’t pivot on spot with that configuration.

PRO
Germany
#22  

"dj sures, good news, it works ok. I have to play with some values to improve the control and something mechanical stuck at the steering servo I have to fix

PRO
Synthiam
#23  

that's good to hear - how's it going now?

PRO
Germany
#24  

heres a short video: https://www.youtube.com/watch?v=CRieRdpSgAA the steering control with horizontal servo works fine. it goes from left to right without problem. Whats is funny is when i first move forward with the joystick the steering goes to full-left then i can control the steering but it springs sometimes shortly left-right !! i cannot go full-right with the steering , duno why. i have the same utility.map for right and left: // Map the speed difference to a servo steering angle // The Utility.map function converts the difference to a range suitable for servo positioning // This maps the max speed difference to a servo range of 1-180 var steeringAngle = Utility.map(diffSpeed, -255, 255, 55, 180);

// Set the servo position based on the calculated steering angle Servo.setPosition(d4, steeringAngle);

It seems to me when the speed is higher, the steering angle on the right is better.Running on the floor, what is the normal behaviort, it is better, it does not spring shortly from left-right. i still can not steer full right,left  is ok. I should invest more time with some values in the script. I'd like to make a test with a ps2 joystick connected to the pc.