Question about auto balancing
11 posts • Page 1 of 1
Question about auto balancing
I have a scene with a guy on a wakeboard. It's really simplistic.
I want to add some code such that when the wakeboard tilts beyond a certain point, the "hips" motor takes a certain action, such as swivels back 5 degrees, and then if it tilts the other direction, then the "hips" motor goes the other way.
I'm not aware of how to constantly measure the angle of an object, and then use an if/then type statement to tell another object such as the motor to take a certain action.
Can anyone post the code to do such? Or at least give me a huge shove in the right direction? I've basically only used onCollide and that is all, and that is mainly for making water. My marble scene I uploaded I did a small speed variable chain where when a lever hits a block, it sets the variable my.scene.speed (or similar) to 3, and then I have the speed of the motor of the chain set to 3, so that is a "remote affect" so to speak, but thats the only thing I've ever done where one object affects another in that way.
I want to add some code such that when the wakeboard tilts beyond a certain point, the "hips" motor takes a certain action, such as swivels back 5 degrees, and then if it tilts the other direction, then the "hips" motor goes the other way.
I'm not aware of how to constantly measure the angle of an object, and then use an if/then type statement to tell another object such as the motor to take a certain action.
Can anyone post the code to do such? Or at least give me a huge shove in the right direction? I've basically only used onCollide and that is all, and that is mainly for making water. My marble scene I uploaded I did a small speed variable chain where when a lever hits a block, it sets the variable my.scene.speed (or similar) to 3, and then I have the speed of the motor of the chain set to 3, so that is a "remote affect" so to speak, but thats the only thing I've ever done where one object affects another in that way.
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
To constantly measure something of an object simply use the update or poststep box in the script menu. Update will still work when sim isn't running.
For the object, where you want to messure the angle, put something like this inside poststep
The angle will be mesured in radians.
For the hip part you could use the bend function. (make sure their is no motors or brakes activated)
Select your hinge and change bend to "true" in the script menu, aswell as the bendConstant to some number (let's say 100)
The last part is more tricky. Try set bendTarget to 3, and you will see your guy will move to a somewhat default position. Try other values till you get a hang of it.
For the if/then/else you could do something like this.
Let's say you want your guy to bend 1 rad forward when the board exceeds an angle of 0.1
in the bendTarget put in something like this
Surely could be explained better, but i hope this helped
For the object, where you want to messure the angle, put something like this inside poststep
- Code: Select all
(e)=>{scene.my.angle = angle}
The angle will be mesured in radians.
For the hip part you could use the bend function. (make sure their is no motors or brakes activated)
Select your hinge and change bend to "true" in the script menu, aswell as the bendConstant to some number (let's say 100)
The last part is more tricky. Try set bendTarget to 3, and you will see your guy will move to a somewhat default position. Try other values till you get a hang of it.
For the if/then/else you could do something like this.
Let's say you want your guy to bend 1 rad forward when the board exceeds an angle of 0.1
in the bendTarget put in something like this
- Code: Select all
{scene.my.angle > 0.1? 2 : 3}
Surely could be explained better, but i hope this helped
- sPetersen
- Posts: 10
- Joined: Sun Apr 10, 2016 6:09 am
Re: Question about auto balancing
Thanks, I cant mess with this where I'm at right now, but I'll try to put it into practice later.
What is poststep?
What is poststep?
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
Nevermind, I found post step. I guess I've seen it in there before but never knew what it was.
Awesome, I've got him thrashing around like a fish whenever the board starts moving. LOL. I need some damping! I'm goofing around with bendConstant, seems to be the ticket.
Thanks a ton for the help, also taught me how to do an if/then although I'm not sure I understand how it works. Right now I have it saying
{scene.my.angle > 0.05? 3 : 3.5}
I assume that means when my angle is greater than .05, it does whatever is after the ?, thats standard. But what does 3: 3.5 mean exactly?
Awesome, I've got him thrashing around like a fish whenever the board starts moving. LOL. I need some damping! I'm goofing around with bendConstant, seems to be the ticket.
Thanks a ton for the help, also taught me how to do an if/then although I'm not sure I understand how it works. Right now I have it saying
{scene.my.angle > 0.05? 3 : 3.5}
I assume that means when my angle is greater than .05, it does whatever is after the ?, thats standard. But what does 3: 3.5 mean exactly?
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
One other question... if I want a high and a low action, how do I stick two if statements into the same bendTarget?
I answered my question from previous btw, where I think the 3 : 3.5 means DO set it to 3, otherwise set it to 3.5, figured that out after just goofing around with the numbers.
So if I can can figure out how to stick two if statements in the one bendTarget, I'm golden!
I answered my question from previous btw, where I think the 3 : 3.5 means DO set it to 3, otherwise set it to 3.5, figured that out after just goofing around with the numbers.
So if I can can figure out how to stick two if statements in the one bendTarget, I'm golden!
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
I got the code to stay without reverting back by putting a semicolon between the two if statements, however, only the last if statement works. The first one seems to be ignored.
{scene.my.angle > 0.05? 3 : 3.5;
scene.my.angle < -.2? 2.5 : 3}
For instance the above code only seems to care if the angle goes below -.2, its ignoring the greater than 0.05 part.
{scene.my.angle > 0.05? 3 : 3.5;
scene.my.angle < -.2? 2.5 : 3}
For instance the above code only seems to care if the angle goes below -.2, its ignoring the greater than 0.05 part.
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
I think what you are trying to achieve is something like this.
- Code: Select all
{ scene.my.angle > 0.05 ? 3.5 : { scene.my.angle < -0.2 ? 2.5 : 3 } }
- sPetersen
- Posts: 10
- Joined: Sun Apr 10, 2016 6:09 am
Re: Question about auto balancing
sPetersen wrote:I think what you are trying to achieve is something like this.
- Code: Select all
{ scene.my.angle > 0.05 ? 3.5 : { scene.my.angle < -0.2 ? 2.5 : 3 } }
OK thanks. In my limited understanding of thyme, it seems like that would wait to trigger until the angle went over .05, right? I want it to trigger when it goes over 0.05 or under -0.2. I'll later try what you said, but it sure seems like that if/then statement wont trigger until the > 0.05 is met.
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
Well, as previously, you were right again
So I'm saying { scene.my.angle > -0.06 ? 1.2 : { scene.my.angle < -0.15 ? -0.5 : 0.5 } }
What it is saying in "normal" language I'm used to...
IF the angle is greater than 0.06, THEN set the axle to 1.2, ELSE IF the angle is less than -0.15, THEN set it to -0.5, ELSE sit steady at 0.5
So I'm saying { scene.my.angle > -0.06 ? 1.2 : { scene.my.angle < -0.15 ? -0.5 : 0.5 } }
What it is saying in "normal" language I'm used to...
IF the angle is greater than 0.06, THEN set the axle to 1.2, ELSE IF the angle is less than -0.15, THEN set it to -0.5, ELSE sit steady at 0.5
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
Got it figured out... uploaded my work to Algobox. I like it
Thanks for the help.
Thanks for the help.
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
Re: Question about auto balancing
Guess I should have included the scene. Here he is, in all his balancing glory!
- grantypoo
- Posts: 36
- Joined: Sat Apr 30, 2016 1:46 am
11 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests