Can friction be added to a joint in a PyBrain ODE simulation? - pybrain

This is my first time asking a question so I'll try my best to include all the necessary information.
I am currently working on a machine learning project using PyBrain. My aim is for a driven pendulum to learn when force should be applied to maximise the amplitude of oscillation.
To do this, I have modelled the system in ODE (Open Dynamics Engine) using the xodetools.py script that is included with PyBrain. While the model works and is simulated, I cannot figure out how to add friction to the pendulum hinge joint.
Some of the example models included with Pybrain (e.g. johnnie_pgpe) redefine a paramater called FricMu in their Task class. I have included this in my code, but no matter what value I set FricMu equal to the system is unchanged (note: if I make it a string the simulation still runs so I presume this parameter is actually doing nothing).
A quick look at the ODE documentation (http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions#Contact) suggests to me that I need to be using a contact joint. This type of joint is not supported by the script so I think would require me to write direct to the XML file.
Can someone with an understanding of either PyBrain or ODE give me some advice on how to increase the damping of my system. Thank you.
Below is the XML code for the pendulum that is imported by PyBrain
<?xml version="1.0" encoding="UTF-8"?>
<xode version="1.0r23" name="pend"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://tanksoftware.com/xode/1.0r23/xode.xsd">
<world>
<space>
<body name="arm">
<transform>
<position y="0" x="0" z="0"/>
</transform>
<mass>
<mass_shape density="125.0">
<box sizex="0.2" sizez="0.2" sizey="0.2"/>
</mass_shape>
</mass>
<geom>
<box sizex="0.2" sizez="0.2" sizey="0.2"/>
</geom>
</body>
<body name="swing">
<transform>
<position y="0" x="0" z="2.2"/>
<rotation>
<euler y="0" x="0" aformat="degrees" z="0"/>
</rotation>
</transform>
<mass>
<mass_shape density="6.36619772588">
<cylinder length="5" radius="0.05"/>
</mass_shape>
</mass>
<geom>
<cylinder length="5" radius="0.05"/>
</geom>
</body>
<joint name="arm_swing">
<link1 body="arm"/>
<link2 body="swing"/>
<hinge>
<axis y="0" x="1" z="0"/>
<anchor y="0" x="0" z="0" absolute="true"/>
</hinge>
</joint>
<joint name="fixedPoint">
<link1 body="arm"/>
<link2 body="swing"/>
<fixed>
</fixed>
</joint>
<geom name="floor">
<plane a="0" c="0" b="1" d="-44.0"/>
</geom>
</space>
</world>
</xode>
<!--odeenvironment parameters
<passpairs>
('arm', 'swing')
<affixToEnvironment>
fixedPoint
<end>
-->

Related

GSAP / TimelineMax SVG Animation of 3D Bar (3 polygons)

I've created a 3D bar in illustrator (see codepen). Now I want to animate it with TweenMax (or TimelineMax) as if it's building up from the bottom to the top.
This is the end result what I need to create:
http://postimg.org/image/pg2drnvch/
I tried a couple of things to make this happen, but without any luck.
Created a clipping-path and then try to change the Y coordinate of the 3 polygons (or wrapped them in a < g >< /g >)
Tried to animate the points of the polygon (http://greensock.com...ing-attrplugin/)
I hope someone can help me with this.
Codepen URL: http://codepen.io/boldcolin/pen/rOPPgP
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="bar_1_" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
width="140.5px" height="366.7px" viewBox="0 0 140.5 366.7" style="enable-background:new 0 0 140.5 366.7;" xml:space="preserve"
>
<style type="text/css">
.st0{clip-path:url(#SVGID_2_);fill:#8BBE3F;}
.st1{clip-path:url(#SVGID_2_);fill:#81A83F;}
.st2{clip-path:url(#SVGID_2_);fill:#A1C63C;}
</style>
<g>
<defs>
<polygon id="SVGID_1_" points="80.3,0 0,40.1 0,336.7 60.2,366.7 140.5,327.1 140.5,30.7 "/>
</defs>
<clipPath id="SVGID_2_">
<use xlink:href="#SVGID_1_" style="overflow:visible;"/>
</clipPath>
<polygon class="st0" points="140.7,169.4 0.2,178.9 0.2,350.2 60.4,380.1 140.7,340.6 "/>
<polyline class="st1" points="60.4,380.1 60.4,205.9 0.2,178.9 0.2,350.2 "/>
<polygon class="st2" points="0.2,178.9 80.5,138.7 140.7,169.4 60.4,209 "/>
</g>
This is an example: http://boldinteractive.nl/raet/bar/
Here I used a white layer on top of the bar which acts like a faux mask. But this is not how I want to make this work..
It's seems impossible to mask a polygon with a polygon and then animate the shape. I'm now using a path (in Illustrator use 'make compound path') and then use this as clipping mask.

Using animateMotion along with keyTimes/keyPoints

I am trying to use non-linear animation rate on an SVG <animateMotion> by using the keyTimes="…" and keyPoints="…" attributes. It does not appear to be working: the animation motion is as linear as can be.
Here's the test file try it!
<svg xmlns="http://www.w3.org/2000/svg" xmlns:x="http://www.w3.org/1999/xlink"
viewBox="0 0 300 200">
<style>
path { stroke:#999 }
circle { fill-opacity:0.5; stroke:black }
</style>
<path id="p" d="M30,160 L270,40" />
<circle id="c" r="5" />
<animateMotion x:href="#c" fill="freeze"
dur="10s"
keyTimes="0;0.1;1"
keyPoints="0;0.9;1">
<mpath x:href="#p" />
</animateMotion>
</svg>
When working the ball should move 90% along the path in the first second, and move the final 10% in the remaining 9 seconds. What do I need to change to get this to work?
I've found another example online that is working correctly, so that I know it's not my OS/browser/version at fault.
(FWIW: Win7x64, Chrome30)
I found my mistake. Even though the default value for calcMode is linear—which is what I want—I didn't read far enough into the spec to see that it's a different default value for <animateMotion> elements.
Adding an explicit calcMode="linear" fixes the problem.
The default calcmode Value for animate Motion is paced not linear;
http://www.w3.org/TR/SVG/animate.html#AnimateMotionElement
And, if calcmode = "paced" is specified, any ‘keyTimes’ or ‘keySplines’ will be ignored.
http://www.w3.org/TR/SVG/animate.html#CalcModeAttribute;
That is why you have not got the the desired output...

SVG animate stroke-dashoffset behaving oddly

I have the following (simplified) SVG:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 120 100" preserveAspectRatio="none" >
<script type="text/ecmascript">
<![CDATA[
function getPathLength(path)
{
alert(path.getTotalLength());
}
]]>
</script>
<rect x="0" y="0" width="100%" height="100%" fill="black"/>
<path id="word" onclick="getPathLength(this);" fill="none" stroke="red" stroke-dasharray="83,83"
d="M 8.90625 3.78125 C 8.5377448 3.8134782 8.1622587 3.965423 7.8125 4.21875 C 6.5568946 6.0743722 5.8966744 8.1275786 5.125 10.15625 C 5.2012388 11.683341 4.3280721 13.093169 4.34375 14.59375 C 3.5435523 17.003468 4.9013748 18.393271 4.125 20.90625 C 3.8249969 23.220653 3.3490969 25.389271 2.96875 27.71875 C 2.775721 29.626027 1.7870007 33.314518 4.6875 33.4375 C 6.6892564 33.267533 8.9446263 33.620664 10.6875 32.53125 C 12.308551 32.345986 13.845824 31.488491 14.96875 30.4375 C 15.336184 29.709947 14.506173 29.249547 15.09375 28.53125 C 15.464699 26.390933 13.333175 28.42555 12.53125 28.4375 C 10.625482 29.096293 8.8511553 29.69647 6.875 29.65625 C 5.6218253 29.22028 6.5435685 27.168764 6.34375 26.03125 C 6.6314225 24.872659 6.8389714 23.78868 7.0625 22.53125 C 7.4982943 20.310119 8.0925706 18.009049 8.5 15.84375 C 9.2688601 14.209069 9.0995411 12.312299 9.71875 10.5625 C 10.027547 9.1134942 10.141384 7.3374588 10.5 5.90625 C 10.999008 4.514099 10.011766 3.6845653 8.90625 3.78125 z ">
<animate attributeName="stroke-dashoffset" begin="0s" from="100%" to="0%" dur="5s" fill="freeze" />
</path>
</svg>
When I click on the path to get the length Firefox v16 reports 82.4... which is what I use for the dasharray. But it starts out with part of the path already drawn, erases it then draws the full path again!? I tinkered witht he dasharay values and it works when I use 110 but I don't know why!
I have not tried other browsers or newer versions of Firefox yet...
NOTE The full problem is a word converted to a path. The path is discontinuous - it has 5 parts (there is a loop in the script forms of 'e', 'z' and 'h' and the first letter 'L' is not joined with the rest). What I want to do is make it look like a laser is drawing the letters. In a previous questions I learned that animating the dashoffset will acheive that effect. I was finally able to convert text to path using Inkscape. Now I am having trouble animating.
I tried animating the dasharray. That works for the correct length, but with the larger full word example (which is 7 letters long and 822 units long) it looks like several paths are in play - not just the 5 discontinuous parts but 9 different paths. When I try to animate the dashoffset on the full word I see NO animation at all - the word just appears fully formed.
Did you think 100% would be 100% of the length of the path? If so that's where you're going wrong as it's 100% of the viewport width. I don't think Opera and Firefox have a bug here, particularly as they happen to be displaying things identically.
Figured it out. I was trying to be cute by using a percentage so that I did not have to put the length in each animate command - all my animates were 100% to 0%. When I replaced the percentages with the actual lengths it worked as expected.
So looks like a bug in the SVG implementations of at least Firefox and Opera as the documentation clearly says you can use percentages...

How do I control the opacity of image mask output created from two images, in SVG?

How do I retain the opacity of an image when creating an image mask using two images in SVG?
As seen in the picture below, the image is nearly transparent - it should be completely opaque. Why is this happening, and how can I force the masked product to have 100% opacity?
Here is the result I am getting:
Here is the mask image I am using:
Here is my code (sorry about the PHP variables):
<svg width="'.$width.'" height="'.$height.'" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<mask id="mask'.$id.'" maskUnits="userSpaceOnUse"
x="0" y="0" width="'.$width.'" height="'.$height.'">
<image id="maskImg'.$id.'" x="0" y="0" width="'.$width.'px" height="'.$height.'px"
xlink:href="images/'.$treatment_url.'" >
</image>
</mask>
<g id="imgGroup'.$id.'">
<rect x="0" y="0" width="'.$width.'" height="'.$height.'" fill="rgba(30,30,30,0.2)" />
<image id="listingImg'.$id.'"
x="0" y="0" width="'.$width.'px" height="'.$height.'px"
xlink:href="'. $img_url .'">
</image>
</g>
</defs>
<use xlink:href="#imgGroup'.$id.'" mask="url(#mask'.$id.')" opacity="1" />';
</svg>
FYI: the <rect> in the <g> group is just to provide a background when the MASKED image is smaller in the x or y dimension than the MASKING image; it does not affect the masking problem I'm having, as I've tried it both ways.
I'm stumped, and appreciate any help!
SVG 1.1 uses luminance masks. A simple and somewhat inaccurate explanation is: White in the mask image gives fully opaque, black gives fully transparent. Some more explanations here. Some more advanced examples of masks with images, see here.
Alpha masks have been proposed and accepted as a requirement for SVG2.

How can I make text orbit along a circular path using HTML5 Canvas?

There are a number of JavaScript snippets that will make text or graphics travel along a circular path with the letters or words always upright.
Example: http://www.dseffects.com/f_scripts.html
I want to have text (or graphics) orbit a point the way the moon orbits the Earth, with one face always toward the center. The following example shows this, but very crudely and not using web fonts.
Example: http://javaboutique.internet.com/text/Manipulation/TextRotor/
I am sure there is a way to modify orbiting code like the first example (only not around the cursor) so that each letter/image keeps one side toward the center (axis).
SVG really is the way to go for this kind of thing. I just whipped this up really quick but at least it works as an example. The HTML part can vary a lot but this is one way.
Put this into an html page:
<iframe src="orbitingText.svg" width="100%" height="100%"></iframe>
Then, create the orbitingText.svg file (it's just a text file with a .svg extension):
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 300 300">
<defs>
<path id="textPath" d="M 150 75 a 75 75 0 1 0 0.00001 0"/>
</defs>
<circle cx="150" cy="150" r="40" stroke="blue" stroke-width="1"></circle>
<text fill="red">
<textPath xlink:href="#textPath" startOffset="0">
<animate attributeName="startOffset" dur="7s" from="0" to="500" repeatCount="indefinite" />
Orbiting Text
</textPath>
</text>
Oh, and if you are worried about cross-browser compatibility, check out this site:
http://code.google.com/p/svgweb/

Resources