Asked — Edited
Resolved Resolved by DJ Sures!

H-Bridge Dc Motor Movement Script

I'm looking to see if I'm scripting correct.

I'm doing the power train to a BB-9. The way the drive is set up is it uses multiple DC planetary motors each with a single motor h-bridge. The motors are dome spin, dome tilt, ball rolling and motor tilt, which causes it to turn and a spin which lets it spin in place to face a different direction.

Since I can only add 1 h-bridge control, I want to use that for the ball rolling and motor tilt, so the other motor controls I'm creating scripts.

Am I doing this correct? Or is there an easier way?

Dome spin is pretty simple since it's a 360 degrees with no stops.


:start
goto(left)
goto(Start)

: Left
Set(d4, on)
Set(d5, off)
Return()
Halt()

I have a second script to spin it right, a third script to stop the spin and a fourth script that centers the dome to a specified ADC reading. If the spinning script is running, running the stop or centering script won't work unless I add ScriptStop to their script, is this correct?


ControlCommand("Script Manager", ScriptStop, "Dome Spin Right")
ControlCommand("Script Manager", ScriptStop, "Dome Spin Left")
:start
goto( Stop)
goto(Start)

: Stop
Set(d4, off)
Set(d5, off)
Halt()

My last question deals with the dome tilting front or back, it does have a range it can go. From my ADC readings, 93 is center, 139 and 38 are the max ranges front and back. Here is one of the tilt direction scripts, using this, will it stop correctly when it reaches the max 139?


$adcSpecified = 139
:start

$adcCurrent = GetADC(adc2)

if ($adcCurrent < $adcSpecified)
goto( front )
endif
if ($adcCurrent = $adcspecified)
goto( Stop)
endif
goto(Start)

: Front
Set(d1, on)
Set(d2, off)
Return()

: Stop
Set(d1, off)
Set(d2, off)
Halt()

This will also have 4 scripts, front, back, stop and center. Also I have 5v going to the EZ-B, D0 and D3 connect to the vcc and ground to the h-bridge and the signal from them I have it connecting to the PWM inputs of the H-Bridges which will be a question for later!

Thanks I added a video of the dome spin test.


ARC Pro

Upgrade to ARC Pro

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

PRO
Synthiam
#9  

What you're trying to make is a servo. You'd like the motor to spin into a position based on the POT reading by GetADC(). This is actually quite simple process, read below...

I have tips...

1. ALL SCRIPTS ARE LOOPING There's no reason for the scripts to loop. Looping a STOP or LEFT or RIGHT, etc... will continually send the SET() commands hundreds of times per second, if not more. The SET() command only needs to be sent ONCE for it to register. Once you send a SET(), it's done, there's no need to repeat.

Remove the LOOP on all of those scripts that only SET() in a loop, such as..

  • dome spin stop
  • dome spin left
  • dome spin right

In fact, I don't know why these scripts exist at all. They have no bounds checking. They just set digital ports for moving a motor in one direction, for ever. I think these three scripts should be deleted.

2. REMOVE or PAUSE ADC GRAPH CONTROLS There are 9 ADC graph controls, not including the GETADC() in the scripts. That's a lot of querying the exact same data over, which is going to interfere with the scripts. If you PAUSE the controls, the scripts will run much faster and reliable. The controls are querying ADC over and over, which is taking priority from the GETADC()

Think of it as having two people asking one person to do the same thing. You have the control asking for GETADC(), then a millisecond later the script is asking for GETADC().

3. Dome Spin Center - WHY IS THERE CONTROLCOMMAND() There are two ControlCommand() to tell the dome to move left AND right at the same time, but that doesn't make any sense... Remove them from this script. The script starts and right away tells two other scripts to do completely opposite things, in loops for ever. Why?

You cannot have a motor spin left and right at the same time. And you certainly can't do that in a loop.

Dome Spin Center should only look exactly like this...


$adcSpecified = 238

:start

$adcCurrent = GetADC(adc1)

# If the adc value is within a range, stop the script
 if ($adcCurrent &gt; $adcSpecified - 2 and $adcCurrent &lt; $adcSpecified + 2)

  Set(d4, off)
  Set(d5, off)

  halt()

elseif ($adcCurrent &lt; $adcSpecified)

  Set(d4, on)
  Set(d5, off)

elseif ($adcCurrent &gt; $adcSpecified)

  Set(d4, off)
  Set(d5, on)

endif

goto(start)

4. DOME TILT FRONT & BACK & CENTER MISSING BOTH DIRECTION MOVEMENTS The Dome Spin Center script that i edited in the above response checks for a range AND moves the dome in two different directions based. This way the motor knows how to actually center. Otherwise, it'll just spin one direction for ever.

Dome Tilt Front should look like this....


$adcSpecified = 115
:start

$adcCurrent = GetADC(adc2)

# If the adc value is within a range, stop the script
if ($adcCurrent &gt; $adcSpecified - 2 and $adcCurrent &lt; $adcSpecified + 2)

  Set(d1, off)
  Set(d2, off)

  halt()

elseif ($adcCurrent &lt; $adcSpecified)

  Set(d1, off)
  Set(d2, on)

elseif ($adcCurrent &gt; $adcSpecified)

  Set(d1, on)
  Set(d2, off)

endif

goto(start)

Dome Tilt Back should look like this...


$adcSpecified = 75
:start

$adcCurrent = GetADC(adc2)

# If the adc value is within a range, stop the script
if ($adcCurrent &gt; $adcSpecified - 2 and $adcCurrent &lt; $adcSpecified + 2)

  Set(d1, off)
  Set(d2, off)

  halt()

elseif ($adcCurrent &gt; $adcSpecified)

  Set(d1, on)
  Set(d2, off)

elseif ($adcCurrent &lt; $adcSpecified)

  Set(d1, off)
  Set(d2, on)

endif

goto(start)

Dome Tilt Center should look like this...


$adcSpecified = 93
:start

$adcCurrent = GetADC(adc2)

# If the adc value is within a range, stop the script
if ($adcCurrent &gt; $adcSpecified - 2 and $adcCurrent &lt; $adcSpecified + 2)

  Set(d1, off)
  Set(d2, off)

  halt()

elseif ($adcCurrent &lt; $adcSpecified)

 Set(d1, off)
 Set(d2, on)

elseif ($adcCurrent &gt; $adcSpecified)

  # I am only guessing here, but you want to reverse the direction?
  Set(d1, on)
  Set(d2, off)

endif

goto(start)

#10  

Thanks DJ Sures!

OK, I added a custom movement, forward and reverse are just setting the digital ports on/off. For the turning, the body tilts side to side and has a pot for left and right tilt end stops. The dome centering worked fine, then it would start to jerk back and forth after testing it a few times, so I'm unsure if it was just a hiccup.

I have a question, I'm going to add a remote joystick to control it down the road. The body tilt stops left or right and trying to center it, I had to hit the stop button about where I thought center was. Is there a way to have it go back to center when the left or right is released? I don't know if I'm over simplifying it, but add something like the centering script of the dome tilt to the stop segment of the body tilt to center the body when the body tilt is stopped?

I added the project and a video of it. You can see it rocking, it's basically on a 10lb bowl with a lazy susan and one last motor that will allow it to spin on it's axis. I still have to hook it up and attach my last h-bridge to control it. I just need to find a spot to mount it.

I need to cleanup the wiring and zip tie them up and I want to hot glue some of the plugs on the hbridges so the don't come free. I have a few body panels left to print and then I can start the assembly!

BB-9eEZB.EZB

PRO
Synthiam
#11  

The motor for tilt when turning - how many volts are you giving it? What amperage is the battery

#12  

It's getting 12v and it's a 20000mAh battery.
It says Current: 400A (Start) 800A (Peak) i have 20 amp fuses on the motors.

#13  

I have a couple more questions.

I've attached my project.

I have my joystick and it controls the movement with joystick 1. When it stops I have the left or right tilt go to center. But when moving forward or backward and I go left or right, I can't figure out how to center the tilt while still moving.

I have all the buttons on the joystick set and they work fine, but I still have the head tilt motions left. I would like to use joystick 2 for it, but it only allows setting ports, no scripting. I tried to see if I could create a virtual servo then add a script to it, but couldn't figure that out if that's the way to go.

Thanks

BB-9eEZB.EZB