Skip to content

Problem with servos in export to arduino #199

Open
@jenncross

Description

@jenncross

This was with CLVP 1.4.383 on Windows 7

I had a set of expressions and sequences that I made originally with a blue hummingbird. I opened them with same robot upgraded with a hummingbird duo and the sequences all seemed to function just fine running from CLVP. However when I exported the sequence to arduino many of the servo values were incorrect.

The "Dino - Chill.xml"

"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE expression PUBLIC "-//CREATE Lab//TeRK//Expression//EN" "http://www.createlab.ri.cmu.edu/dtd/terk/expression.dtd">
<expression version="1.0">
   <services>
      <service type-id="::TeRK::motor::VelocityControllableMotorService">
         <operation name="setVelocity">
            <device id="0">
               <parameter name="velocity"><![CDATA[204]]></parameter>
            </device>
         </operation>
      </service>
      <service type-id="::TeRK::servo::SimpleServoService">
         <operation name="setPosition">
            <device id="3">
               <parameter name="position"><![CDATA[219]]></parameter>
            </device>
            <device id="1">
               <parameter name="position"><![CDATA[219]]></parameter>
            </device>
            <device id="0">
               <parameter name="position"><![CDATA[90]]></parameter>
            </device>
         </operation>
      </service>
      <service type-id="::TeRK::led::FullColorLEDService">
         <operation name="setColor">
            <device id="0">
               <parameter name="red"><![CDATA[0]]></parameter>
               <parameter name="green"><![CDATA[0]]></parameter>
               <parameter name="blue"><![CDATA[255]]></parameter>
            </device>
            <device id="1">
               <parameter name="red"><![CDATA[0]]></parameter>
               <parameter name="green"><![CDATA[0]]></parameter>
               <parameter name="blue"><![CDATA[255]]></parameter>
            </device>
         </operation>
      </service>
   </services>
</expression>

became

void DinoChill(){
    hummingbird.setMotor(1,-204);
    hummingbird.setServo(4,-219);
    hummingbird.setServo(2,-219);
    hummingbird.setServo(1,-90);
    hummingbird.setTriColorLED(1,0,0,255);
    hummingbird.setTriColorLED(2,0,0,255);
}

The first issue is that the values sent to the servo became negative when in the XML the value was positive. The second issue is that the current setServo function takes the servo position as 0-180 degrees (not the 0-255 value stored in the xml expression), so that conversion was omitted.

Another example, "Dino - Mouth Open"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE expression PUBLIC "-//CREATE Lab//TeRK//Expression//EN" "http://www.createlab.ri.cmu.edu/dtd/terk/expression.dtd">
<expression version="1.0">
   <services>
      <service type-id="::TeRK::servo::SimpleServoService">
         <operation name="setPosition">
            <device id="1">
               <parameter name="position"><![CDATA[173]]></parameter>
            </device>
            <device id="3">
               <parameter name="position"><![CDATA[173]]></parameter>
            </device>
         </operation>
      </service>
   </services>
</expression>

became

void DinoMouthOpen(){
    hummingbird.setServo(2,173);
    hummingbird.setServo(4,173);
}

which suffered from not being converted to the 0-180 range, but was oddly not made negative?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions