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
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,



Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

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.
@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.

United Kingdom
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
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.
Just to be sure. You are using H-bridge PWM Movement. In settings Left and Right PWM are both set to D4?

On the Movement Panel itself, on the right side, there are two slide controls. These set the max speed of each PWM channel (which are the same for you since you have the same port connected to both).

If you are just using an H-Bridge Movement Panel, it doesn't allow PWM control in the panel, just in scripting, and may not achieve what you want.

United Kingdom
Yup. Using the PWM panel with sliders.
OK. I'll get a joystick plugged in tonight or this weekend and see if I can get it figured out.
United Kingdom
Nice one. Thanks Alan. ;)
I am not sure how much help I am going to be. I plugged in my joystick, an old Microsoft Sidewinder USB joystick, and it did exactly what it was supposed to do. Pushing the stick a little set the speed controls to low, and Roli crawled away slowly. Pushing the stick further, brought the speed up to max and he took off down the hall. Same thing with each direction. This joystick has a wide range of motion, so the speed changes were very smooth.

One thing I did notice, is in the joystick control, there is a checkbox to "use variable movement speed". do you have that checked?

However using the H-bridge movement panel, I could not set a maximum speed. The joystick over-rode the speed I had set in my init script as soon as I pushed it to maximum.

I think for setting a maximum speed you may need a custom movement panel, and something similar to the sabertooth ramping scripts that Rich wrote for Gwen's project. Scripts attached to the Sabertooth Ramping project on EZ-Cloud (it will obviously need to be modified to send the correct commands to the H-bridge instead of the SendSerial() commands it uses now).

Either that, or get a joystick with a wider range of motion so that you have more control. What brand/model joystick are you using?

United Kingdom
Thanks for trying it out Alan. Yup, that was exactly the same thing that was happening to me, with the joystick over-riding the init script I had. Yes I do have the vairable speed tick box checked. The brand of joypad I'm using is a CSL C210 wireless pad.

I'm having a little with the drive motors at the moment, where the drive along for a short while then quickly gradually lose power, I wait a few seconds, then they drive normal and slowly lose power again, so I think my 12v drivetrain battery is knackered which is now making testing a little difficult (I think that's the cause anyway). Just ordered a new 11.1v LiPo which should be with me Tuesday so I'll carry on experimenting then and keep you informed.
OK. I have some other stuff I want to work on this weekend, and can't dedicate the whole weekend to robotics, but if I have some time I will try to adapt the Sabertooth Ramping project to work with an L298N with PWM speed control instead.

This will actually be useful for my Roli as well. I have a little pocket size BT joystick and it doesn't have proportional output on the direction buttons. They just emulate hitting the arrow keys on the keyboard, so if I create this custom Movement Panel and script, it will work for me too.

United Kingdom
Well after tring a few script examples I'm still not having much luck solving this. I've come across a new issue here which is not helping matters. The couple of things I tried mentioned in this thread still moves the sliders in the Movement Panel back to full. Really not sure what to do now. *confused*
I haven't had as much free time as I thought, and had some other priorities with my Roli, but this is still on my todo list. I am certain it is solvable with a custom Movement Panel and scripting similar to what we did with the Sabertooth Ramping scripts Rich wrote for Gwen's B9.

Now, since it turns out you need a more powerful H-Bridge, anything I come up with will need to be adapted to the commands for that bridge, but we'll cross that bridge when we get there (or if you decide to bite the bullet and get a Sabertooth, things are much simpler. It turns out Rich's ramping script was superfluous because you can hook the Saberooth up to a TTL adapter and give it a command to tun auto-ramping on, and we can make a custom Movement Panel that has whatever you want as your max speed be the command that gets sent to move in that direction).

United Kingdom
I might be looking to get a sabertooth early next year if there's no other way. For now I've just ordered a 10amp H-bridge which should solve my other problem.

I was thinking, all we really need for this is a setting in the Movement Panel config menu, where we move a slider control to where we want it set, and tick a check box next to it saying "use this slider setting for the max speed". Unchecked, the slider/speed would go back to default maximum. Something DJ may consider adding to his to do list. Just a thought to make things a little easier perhaps. ;)
That tends to be what happens here. Several of us will start discussing how to achieve something with existing features, and just about the time we have it worked out, DJ will add it as a feature.

I think it is one way he judges the priority of things. The more we are willing to work for it, the more likely it is that other customers will want it too.

United Kingdom
I'm more than certain that an adaptation of the custom Movement Panel on Gwen's B9 would achieve what is needed here.

Just refresh my memory (without me re-reading the topic). What's the end goal? What must be achieved?
Goal: Conrinue to allow speed ramping when using a Joystick to control an HB 298n, but be able to set a max speed lower than speed(256) or pwm(100). Today, the Joystick over-rides the speed setting in the Hbridge with PWM movement panel.

Should be modifiable to work with the new H-Bridge steve ordered due to the 298n not being sufficient for his motors.

United Kingdom
Well I got my motor controller and have just installed, had a play around with the joystick again trying to finally sort out the max speed issue, and finally solved it with Rich's help in another thread in post 4 .;)

I opened a Modified control panel and inserted the following scripts in to the config menu.


To Stop...

Set(D1, On)
Set(D3, On)
PWM(D0, 0)
PWM(D2, 0)

To go forwards...

Set(D1, On)
Set(D3, On)
PWM(D0, 60)
PWM(D2, 60)

and to go in reverse...
Set(D1, Off)
Set(D3, Off)
PWM(D0, 60)
PWM(D2, 60)

This works like a charm. I haven't added left of right code as I have a separate servo for this. Hopefully this will help you out too Alan (let me know how you get on), and thanks again to Rich for your help :). I just need to stop the wheels spinning when I power the EZB and waits to make a connection, which I have asked about here in post #15.
Oh, that was much simpler than I expected.
[edited to remove question that made no sense once I opened ARC and looked at the options]

United Kingdom
Much simpler than I expected too :). Only thing is that I have lost vairable speed from the joystick, but Rich did leave a script with some math to deal with this which I may play around with.