Asked
— Edited
I am attempting to get a 4-in-1 sensor to work as I need it to and not have much success - I need a hand. I am trying to get the 4- in-1 sensor to drive 2 servos to keep something level/plumb. I have the servos set to go up or down depending on the sensor readings. The problems I'm having are;
- It will kind of work for a short time but will only drive one servo at a time even if both should move,
- The Y axis stops working after a few minutes,
- Then everything stops working,
- For some reason the 'Sleep' command above the 'loop' is run each time and anything else put there -except the first line. I am running the sensor on a EZBv4/2. My code is a modified version of one from a JD project. Here's my code;
ControlCommand("MPU9150", Init)
sleep(1000)
:loop
#Added these because $AccelX and $AccelY were not recognized later in the script for some reason.
$XAccel = $AccelX
$YAccel = $AccelY
if ("x" =0)
print(1)
sleep(2000)
goto(loop)
endif
ControlCommand("MPU9150", RunOnce)
print("x: " + $XAccel)
print("y: " + $YAccel)
if ($XAccel > 1000)
ServoUp(D1,10)
Servospeed(D1,2)
ELSEif ($XAccel < -1000)
ServoDown(D3,10)
Servospeed(D3,2)
Endif
if ($YAccel > 1000)
ServoUp(D3,10)
Servospeed(D3,2)
ELSEif ($YAccel < -1000)
ServoDown(D3,10)
Servospeed(D3,2)
Sleep(500)
endif
sleep(1500)
goto(loop)
Has anyone played with these sensors much and got them working? I know I have a lot to learn about them so your assistance will be appreciated.
Thanks
Sounds as though maybe your servo’s position is not being updated, or too much load on the servo?
Are you using digital or analogue servos?
I know the ezb will work with both, but digital would be much better, hope you find the problem soon. : )
Hi @bhouston,
My guess is the way you state your servo speeds? From the Script help section:
Your stating your servo speeds "after" you set your position.
@bhouston,
What you have in mind ?
Are you trying to detect motion or track the orientation ?
Your code reads the IMU every 1.5 seconds. A lot of things can happen in 1500 milliseconds.
@Newagetomy, I'm using EZ Robot HD servos @Dave, I'll clean that up, thanks. @ptp, I am trying to detect motion. The robot starts out level, If the robot is leaned to the left or the right or to the front or back, that will be detected. Then the servos will move the axis effected back to level. I realize that 1500 milliseconds is a long time- I'm just trying to get it to work, then I'll shorten the time.
I've been working on this again today. If I run this code, it works great;
But I need 2 servos to run in the code. If I run this code;
It does not move either of the 2 servos and the code runs lines of code outside of the 'loop'. This is what that looks like;
I still looking for some help before I give up on these sensors. Thanks
Use Blockly so you can visually see the logic
Bob,
Try the code below and let us know the output:
@DJ, I'll try that. @ptp, Here's a snipet of what I get;
I worked for a short time then quit working