Angular Velocity > 0 But Objects Not Spinning

Check out the GIF below.  Top-left of screen is reporting on total angular velocity for all gears involved except for the motor-gear (far-left).

All of the wheels have stopped moving, but total angular velocity doesn’t equal zero.  GIF ends just as wheels are stopping, but total angular velocity still hasn’t dipped below 210. 

Any ideas?

https://gyazo.com/887eb778fd1a04d086a9769dbaefb591

I’m calculating the total in a FOR loop like this:

totalAnglularVelocity = totalAnglularVelocity + math.floor(math.abs(gear.angularVelocity))

Cheers.

Show us the code where you make the object and the code where you set the angular velocity.

Gear are being driven by physics from the left-most gear (motor) and a combination of gear joints. I’m not setting angular velocity manually. 

Gears are created dynamically… Below is an excerpt of creating the physics bodies:

newGear.physicsParams = {radius = newGear.radius, density=10, friction=1, bounce=0.001, filter = gearFilter} physics.addBody(newGear, "dynamic", newGear.physicsParams) --Set physics params consistently newGear.angularDamping = 0 newGear.linearDamping = 0 --Gear collision handler newGear.collision = GearCollisionListener newGear:addEventListener( "collision" ) newGear:addEventListener( "touch", GearTouchHandler ) table.insert(gearPuzzle.gears, newGear) gearPuzzle.groupMain:insert( newGear )

Each time a gear connected to one that has been connected to the motor, a Gear Joint is created between the two.  Below is an excerpt from the GearCollisionListener() function:

--If gear initiating collision is on axle and then create a gear joint between the two gears --Will only fire if both gears are "pinned" to wall/axle (pivotJoint exists) if (#self.gearJoints == 0 and (self.pivotJoint ~= nil and event.other.pivotJoint ~= nil)) then --Need to delay physics calls when inside listeners function CreateGearJoint() print("GEAR PUZZLE: GEAR JOINT CREATED!!") if (self.pivotJoint ~= nil and event.other.pivotJoint ~= nil) then --Make sure both gears know about joint (so both can be removed when gear is removed) local gearJoint = physics.newJoint("gear", event.other, self, event.other.pivotJoint, self.pivotJoint, 1) self.gearJoints[#self.gearJoints+1] = gearJoint event.other.gearJoints[#event.other.gearJoints+1] = gearJoint AdjustGearLoopVolume() --Add to master joint tracker for easy cleanup table.insert(gearPuzzle.joints, gearJoint) end end timer.performWithDelay( 50, CreateGearJoint, 1 ) end

Each object keeps track of its own Gear Joints, so total angular velocity is being calculated like this:

local numGearsInMotion = 0 local totalAnglularVelocity = 0 for i,gear in pairs(gearPuzzle.gears) do if (#gear.gearJoints \> 0) then numGearsInMotion = numGearsInMotion + 1 totalAnglularVelocity = totalAnglularVelocity + math.floor(math.abs(gear.angularVelocity)) end end

One weird thing I’ve noticed is that once the gears have stopped, every gear I add or remove to the chain adds or removes “29” to/from the angular velocity:

https://gyazo.com/9060746dc85588ec6f1f61e15841fba1

I’m not seeing anything.

Note:  Please replace tabs with spaces (3 is perfect) when posting code here.  For whatever reason, tabs pop out to about 8 spaces making code with tabs  a PITA to read.

I know you’ve been working on this for a bit, but I have to wonder if NOT using physics might be easier to control/handle?

It will require a little math, but once you get the math worked out, this should be straight-forward.

I worry that by depending on Physics, you’re opening yourself up to the possibility of failure should even the smallest thing change or go wrong in the future.

However, if you code up the calculations yourself, it will be solid forever.

Noted.  If I wasn’t so damn close to finishing I may have done that. 

Forums here are dead except for the one roamer…  What happened to Brent S.?

Figured it out.  I guess my maxMotorTorque value was too high.  Motor torque wasn’t reaching max, which is why I think the angular velocity wasn’t hitting zero.

Setting maxMotorTorque = 1000 fixed the problem.

Show us the code where you make the object and the code where you set the angular velocity.

Gear are being driven by physics from the left-most gear (motor) and a combination of gear joints. I’m not setting angular velocity manually. 

Gears are created dynamically… Below is an excerpt of creating the physics bodies:

newGear.physicsParams = {radius = newGear.radius, density=10, friction=1, bounce=0.001, filter = gearFilter} physics.addBody(newGear, "dynamic", newGear.physicsParams) --Set physics params consistently newGear.angularDamping = 0 newGear.linearDamping = 0 --Gear collision handler newGear.collision = GearCollisionListener newGear:addEventListener( "collision" ) newGear:addEventListener( "touch", GearTouchHandler ) table.insert(gearPuzzle.gears, newGear) gearPuzzle.groupMain:insert( newGear )

Each time a gear connected to one that has been connected to the motor, a Gear Joint is created between the two.  Below is an excerpt from the GearCollisionListener() function:

--If gear initiating collision is on axle and then create a gear joint between the two gears --Will only fire if both gears are "pinned" to wall/axle (pivotJoint exists) if (#self.gearJoints == 0 and (self.pivotJoint ~= nil and event.other.pivotJoint ~= nil)) then --Need to delay physics calls when inside listeners function CreateGearJoint() print("GEAR PUZZLE: GEAR JOINT CREATED!!") if (self.pivotJoint ~= nil and event.other.pivotJoint ~= nil) then --Make sure both gears know about joint (so both can be removed when gear is removed) local gearJoint = physics.newJoint("gear", event.other, self, event.other.pivotJoint, self.pivotJoint, 1) self.gearJoints[#self.gearJoints+1] = gearJoint event.other.gearJoints[#event.other.gearJoints+1] = gearJoint AdjustGearLoopVolume() --Add to master joint tracker for easy cleanup table.insert(gearPuzzle.joints, gearJoint) end end timer.performWithDelay( 50, CreateGearJoint, 1 ) end

Each object keeps track of its own Gear Joints, so total angular velocity is being calculated like this:

local numGearsInMotion = 0 local totalAnglularVelocity = 0 for i,gear in pairs(gearPuzzle.gears) do if (#gear.gearJoints \> 0) then numGearsInMotion = numGearsInMotion + 1 totalAnglularVelocity = totalAnglularVelocity + math.floor(math.abs(gear.angularVelocity)) end end

One weird thing I’ve noticed is that once the gears have stopped, every gear I add or remove to the chain adds or removes “29” to/from the angular velocity:

https://gyazo.com/9060746dc85588ec6f1f61e15841fba1

I’m not seeing anything.

Note:  Please replace tabs with spaces (3 is perfect) when posting code here.  For whatever reason, tabs pop out to about 8 spaces making code with tabs  a PITA to read.

I know you’ve been working on this for a bit, but I have to wonder if NOT using physics might be easier to control/handle?

It will require a little math, but once you get the math worked out, this should be straight-forward.

I worry that by depending on Physics, you’re opening yourself up to the possibility of failure should even the smallest thing change or go wrong in the future.

However, if you code up the calculations yourself, it will be solid forever.

Noted.  If I wasn’t so damn close to finishing I may have done that. 

Forums here are dead except for the one roamer…  What happened to Brent S.?

Figured it out.  I guess my maxMotorTorque value was too high.  Motor torque wasn’t reaching max, which is why I think the angular velocity wasn’t hitting zero.

Setting maxMotorTorque = 1000 fixed the problem.