United Kingdom
Asked — Edited
Resolved Resolved by Rich!

Setting Max Speed For H-Bridge Motors

Hi there.

So, I have 2 drive motors running through a L298 H-bridge. I have set these up with a "H-bridge with speed control" Movement Panel and all is working well, but here's where I need a little guidance.

At the moment the motors are controlled via joystick 1. I have the variable speed box checked and the sensitivity set right down to the lowest option in the joystick 1 config menu. Problem is it is still quite sensitive so I need to reduce the maximum motor speed by at least half when the joystick is fully pressed. Is this achievable, and if so how do I go about doing this? I'm guessing there is some scripting involved somewhere. I have had a look through the script menu but I don't know what I need to use. I will also need a reduced maximum speed for these motors for when for when things go autonomous when I get round to setting that up.

Many thanks,

Steve.


ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

United Kingdom
#9  

I thought something similar to this might work (but didn't have much luck).


:loop
IF ($Joysticky1 = 1)
setspeed(50)
sleep(1000)

ELSEIF ($joysticky1 = -1)
setspeed(50)
sleep(1000)
ENDIF
sleep(1000)
goto(loop)

#10  

You are going to make me plug in a joystick to help figure this out (I have just been using the Movement Panel and the arrow keys on my keyboard, and the touch movement object, not an actual joystick).

I'll play around tonight or this weekend to see if using a joystick changes anything.

Alan

United Kingdom
#11  

Use PWM() rather than SetSpeed()

However that wont give analogue speed control. You need to throw some math at it.


:loop

IF ($Joysticky1 = 1)
  PWM(D4,50)
ELSEIF ($joysticky1 = -1)
  PWM(D4,50)
ENDIF

sleep(1000)

goto(loop)

Or with the math


:loop

# Check and convert negative number to positive if needed
IF($joysticky1 < 0)
  # If negative multiply by -1 to change to positive
  $PWMSpeed = $joysticky1 * -1
Else
  # If positive just save the value
  $PWMSpeed = $joysticky1
EndIf

# Convert the value to usable PWM value
$PWMSpeed = $PWMSpeed * 50
# Make it an integer
$PWMSpeed = Round($PWMSpeed, 0)

# Set the PWM
PWM(D4,$PWMSpeed)

# Sleep
sleep(50)

# Loop back
goto(loop)

United Kingdom
#12  

@the Techguru.

Cheers Alan. Got to get this sorted before K-9 runs in to someone and breaks their ankle eek.

@Rich.

Oh no, not maths. I hate maths confused. Jokes aside, I'll have a look at that script a bit later and see if that will work for me. cheers.

#13  

If all else fails, you could use a custom Movement Panel and have the forward command turn on the forward trigger ports, and set the pwm to 50.

#14  

@Rich, Just curious why you say not to use SetSpeed. It is working well for setting the speed of my Roli. Or are you trying to have the speed increase the further the joystick is pushed, in which case modifying the PWM may be the way to go.

@Steve G. Everything we solve for you will be used in my Steampunk K9 project, so better for me if we get it sorted now rather than after I start my build (particularly since I expect I will be using wheelchair motors and a Sabertooth since I expect my bot to be very heavy, so I want absolute control over his speed and direction to prevent killing someone or breaking furniture.....)

I am basically using Roli as a test bed for the bigger project.

Alan

United Kingdom
#15  

Yes, faster speed the further the stick is pushed. SetSpeed() should work too but it requires the Movement Panel to be set up correctly, I'm not convinced that in this case it is.

United Kingdom
#16  

Just to confirm, the H-bridge Movement Panel is set up correctly. I changed the nessasery servo ports and when using the joystick, the wheels/motors do exactly what they should. The joystick I'm using does support vairable speeds and it does work. It's just to sensitive even with sensitivity turned right down (to 5 or 0.5 whatever the minimum is). just need to reduce the overall max speed.