motor control

If you have problems installing or running Algodoo, have found a bug or need in-game help - this is it!

motor control

Postby kbrtom » Thu Mar 31, 2011 2:12 am

I'm new to all this but trying to learn - this being said I am trying to control a motor to (example) rotate 15 (?) degrees, reverse, rotate the same amount and continue this action. Anyone help? Thanks
kbrtom
 
Posts: 9
Joined: Thu Mar 24, 2011 12:40 pm

Re: motor control

Postby racergonemad » Thu Mar 31, 2011 7:17 am

Theres no way to tell thyme what the angle of a geom is but their is an alternative way to imput the angle of an object using a mechanized system with variables.

1. open the console by pressing ~ next to the number 1.

2 type the following:
Code: Select all
scene.my.pos1 := [0.0]; scene.my.pos2 := [0,0]; scene.my.hingeState := false


3. make 2 small circles on the box you want to rotate. make sure the circles are directly lined up vertically with the hing controlling everything. This is important. Also, try to make them as far away from eachother as possible. It will increase the accuracy of the system.

4. make 2 off centered hinges on both circles - One for each circle - and make the motors true, the motor speeds 600, and the motor strengths +inf.

5. make a pair of boxes that will constantly collide with the circles. Dont clone them or else it wont work. Fix them to the main box that you want to rotate 15 degrees.

6. on the top box'es onCollide, type the following:
Code: Select all
(e)=>{scene.my.pos1 := e.pos}


and on the bottom one type:
Code: Select all
(e)=>{scene.my.pos2 := e.pos; scene.my.pos1(0) - scene.my.pos2(0) >= 0.5 ? {scene.my.hingeState := true} : {}; scene.my.pos2(0) - scene.my.pos1(0) >= 0.5 ? {scene.my.hingeState := false} : {} }


7. On the hinge that controlls the acutall angle of the main box, go to its script menu and type the following where you see ccw. Remember to make the motor true:
Code: Select all
{scene.my.hingeState}


8. Start the sim. If you want to change the range of motion, go to the bottom box'es onCollide and play around with the two numbers that say 0.5. The closer to zero, the less range it has.

Hope this helped. Please let me know, :)
Attachments
phun picture.png
This is a picture of what it should look like
(70.24 KiB) Downloaded 1 time
My signature is worth a lot of money, So I'm gonna put this stamp instead:
[$20 PER AUTOGRAPH]
racergonemad
 
Posts: 26
Joined: Tue Aug 17, 2010 7:37 am

Re: motor control

Postby Kilinich » Thu Mar 31, 2011 10:52 am

holy... :wtf: too complicated.

Simple idea is to make scene.my. variable like scene.my.reverse := false, set motor's ccw property to {scene.my.ccw} and switch value within on collide. For example one "limit" box's onCollide = (e) => {scene.my.ccw = true}, another {... = false}.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: motor control

Postby kbrtom » Thu Mar 31, 2011 2:25 pm

thanks for the help - I did exactly as you said and triple checked the script but the box just rotates in the direction of the motor without any hesitation at the speed at which it is set (default) see attachment
Attachments
motor control.phz
(15.42 KiB) Downloaded 40 times
kbrtom
 
Posts: 9
Joined: Thu Mar 24, 2011 12:40 pm

Re: motor control

Postby Kilinich » Thu Mar 31, 2011 2:46 pm

Incorrect code.
You forget "?" after condition.

Code: Select all
(e)=>{
    scene.my.pos2 := e.pos;
    scene.my.pos1(0) - scene.my.pos2(0) >= 0.5({scene.my.hingeState := true})(:)({});
    scene.my.pos1(0) >= 0.5({scene.my.hingeState := false})(:)({})
}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: motor control

Postby kbrtom » Thu Mar 31, 2011 7:00 pm

Gottcha, thanks :crazy:
kbrtom
 
Posts: 9
Joined: Thu Mar 24, 2011 12:40 pm


Return to Help / Bug reports

Who is online

Users browsing this forum: No registered users and 4 guests