Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rollicking Ruby Robots Rule the World

Rollicking Ruby Robots Rule the World

We don't see it all the time but robots that make our lives easier are already here with us. While they look nothing like the Transformers (cool!) or the Terminator (cool but scary), they affect our lives just as deeply. They assemble our cars, package our goods, manufacture our electronics, harvest our crops, clean our floors, drive our cars and even fight our wars (scary again).

In this talk, we want to show you how you can create and program your own autonomous robots using Ruby. We will show you how we built an inexpensive hexapod spider robot and how we wrote the software to control it, using Ruby.

Sau Sheong Chang

June 04, 2015
Tweet

More Decks by Sau Sheong Chang

Other Decks in Technology

Transcript

  1. MG995 High Speed Metal Gear Dual Ball Bearing Servo The

    unit comes complete with 30cm wire and 3 pin 'S' type female header connector that fits most receivers, including Futaba, JR, GWS, Cirrus, Blue Bird, Blue Arrow, Corona, Berg, Spektrum and Hitec. This high-speed standard servo can rotate approximately 120 degrees (60 in each direction). You can use any servo code, hardware or library to control these servos, so it's great for beginners who want to make stuff move without building a motor controller with feedback & gear box, especially since it will fit in small places. The MG995 Metal Gear Servo also OperaCng)temperature)range:)U20)to)60)deg)C) Stall)torque:)11)kgcm) Current)drain:)450mA)(no)load),)1)–)2A)(normal)load)) )
  2. Models)the)servo) class Servo def initialize(n) @number = n end def

    rotate(deg) points = (2000 * deg.to_f/180) + 500 "##{@number}P#{points.to_i}" end end
  3. Models)a)3DOF)leg) class Leg3DOF def initialize(side, coxa, femur, tibia) @side =

    side @coxa = Servo.new coxa @femur = Servo.new femur @tibia = Servo.new tibia end # rotate the servos accordingly def actuate(c, f, t) c, f, t = *convert(c, f, t) return @coxa.rotate(c) + @femur.rotate(f) + @tibia.rotate(t) end
  4. Models)a)3DOF)leg) # if the leg is on the left side

    of body, flip def convert(c, f, t) if @side == :right return [c, f, t] elsif @side == :left return [c, f, t].map {|deg| 180 - deg} end end end
  5. Create)the)shapes) // Body shapes[0] = new btBoxShape(btVector3(0.4,0.1,0.6)); for (int i=0;

    i<NUM_LEGS; i++) { // femur shapes[1 + 3*i] = new btCapsuleShape(btScalar(0.10), btScalar(fLegLength)); // tibia shapes[2 + 3*i] = new btCapsuleShape(btScalar(0.08), btScalar(fForeLegLength)); // coxa shapes[3 + 3*i] = new btCapsuleShape(btScalar(0.08), btScalar(fCoxaLength)); }
  6. Create)the)rigid)bodies) btVector3 vBoneOrigin; // rigid body position vBoneOrigin = btVector3(-0.5

    - fLegLength / 2, fHeight, (i-1)*0.6); transform.setIdentity(); transform.setOrigin(vBoneOrigin); // rotation transform.setRotation(btQuaternion(btVector3(0,0,1), M_PI_2)); bodies[1+3*i] = localCreateRigidBody( btScalar(0.01), // mass offset*transform, // transform matrix shapes[1+3*i]); // bind a shape
  7. Add)hinge)constraints) localA = btTransform(vQ, vBoneOrigin); localB = bodies[3+3*i]->getWorldTransform().inverse() * bodies[0]->getWorldTransform()

    * localA; hingeC = new btHingeConstraint(*bodies[0], *bodies[3+3*i], localA, localB); joints[2+3*i] = hingeC; hingeC->enableMotor(true); hingeC->setLimit(-M_PI_6,M_PI_6); hingeC->setMaxMotorImpulse(1000); world->addConstraint(joints[2+3*i], true);