Well I've made some progress on the rotating blade project. After
poking around in the software and getting a feel for things I decided
that since what I needed could be accomplished by creating another
component in the 'block.c' file. I duplicated the 'ddt'
(discriminator) function and called it 'dir' (directionator :-)
(starts to sound like a German Doppelbock or something) I then added
two input pins and an output pin to it's data structure, along with some
storage. Once compiled I use hal commands to load my 'dir' component,
connect it to a thread, and connect Xpos-cmd and Ypos-cmd to my new
inputs "dir.0.in_x" and "dir.0.in_y". I then monitor the output with
halmeter. At this I'm getting reasonable output from it. When the x
axis is stationary and y is traveling 'north' I get "90.0" degrees, when
y goes 'south' I get -90.0, likewise with the X axis, and when cutting
the sample spiral the direction seems to be reasonable as it goes
around. I have more to do to convert it to whatever the rotation axis
requires as input, and to make sure I don't tell it to turn 359 degrees
one way when turning 1 degree the other would do it. I also have to
come up with a homing function.
I need a reality check though. For one thing, when assigning something
to the 'commanded' position of a rotary axis, do you give it an absolute
angle or a relative angle change? If it's pointing at a 45 and I want
it to point straight up do I assign it 90 degrees or tell it to turn
another 45 degrees?
I'm also assuming that when I get things working I'll just have to use
hal to connect the output pin from my component to 'Apos-cmd' ( or
something like that) , right?
Here's my dir_funct, although incomplete. And I'm still trying to grasp
what you meant by the 'turns = floor....' stuff. I hard coded most of
the stuff that could be passed as parameters too, for testing.
static void dir_funct(void *arg, long period)
{
dir_t *dir;
double dx,dy,theta,turns,speed,dth;
/* point to block data */
dir = (dir_t *) arg;
/* save old out */
dir->old_theta = *(dir->out);
/* calculate output */
dx = *(dir->in_x) - dir->old_x;
dy = *(dir->in_y) - dir->old_y;
dir->old_x = *(dir->in_x);
dir->old_y = *(dir->in_y);
speed = hypot(dx,dy);
if (speed < 0.0000001) return;
// turns = floor((dir->old_theta + M_PI) / (2 * M_PI));
theta = atan2(dy,dx); // + turns * 2 * M_PI;
// dth = theta - dir->old_theta;
// if (dth > M_PI)
// theta -= 2*M_PI;
// else if
// (dth < -M_PI) theta += 2*M_PI;
*(dir->out) = (float)(theta * (180/M_PI));
}
thanks,
Steve
Steve Andrusz wrote:
> Wow, thanks for all the help. I'm going to have to study up and get my
> system to the point that I can compile and dive in.
>
> I needed more stuff to read about too ;-)
>
> Steve
> <snip>
>
> Jeff Epler wrote:
>
>> 44
>> HAL already includes 'ddt', which computes the change in a signal per
>> unit time.
>>
>> In "C" there's atan2(y,x) which is like atan(y/x) but gives an angle
>> ranging from -pi to +pi, instead of -pi/2 to +pi/2
>>
>> The component you'd write would look something like this:
>> /* ------------------------------------------------------------------ */
>> component rotator;
>>
>> pin in float dx;
>> pin in float dy;
>> pin out float out;
>>
>> param rw float minspeed = .01
>> "Below this speed in units per second, output is held steady";
>> param rw float scale = 1
>> "Set to 1 for radians and 180/pi for degrees";
>>
>> function _;
>> ;;
>> MODULE_LICENSE("GPL");
>>
>> #include "rtapi_math.h"
>>
>> FUNCTION(_) {
>> double speed = hypot(dx, dy);
>> double theta, dth, old_out, turns;
>>
>> if(speed < minspeed * fperiod) return;
>>
>> old_out = out;
>> turns = floor((old_out + M_PI) / (2*M_PI));
>> theta = atan2(dy, dx) + turns * 2*M_PI;
>>
>> dth = theta - old_out;
>> if(dth > M_PI) theta -= 2*M_PI;
>> else if(dth < -M_PI) theta += 2*M_PI;
>>
>> out = theta * scale;
>> }
>> /* ------------------------------------------------------------------ */
>> in testing, this appeared to get the angle change requirement right.
>> Instead of using the old 'out' value, you might want to have a
>> 'last_angle' input, which would be the feedback position of the angular
>> axis. This way, the choice about which way to turn is based on where
>> the blade actually is, not where the computer would like it to be.
>>
>> Jeff
>>
>> -------------------------------------------------------------------------
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> Emc-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/emc-users
>>
>>
>>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Emc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/emc-users
>
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users