Most of the time.
So, recently we’ve had a project involving x & z motion, using a few servo drives and some controllers.
The problem came up, that we needed to average 3 angles together, to find a proper location to move…
So, this introduces an excellent time for real math…
Lets take for example this:
Average the following Angles: 0,359,1. The expected answer is actually 0 . Not, 120.
Why? because we care about the Direction, Not the Amount of Rotation actually moved.
So… This is where you actually get to use those trig fuctions to turn everything into vectors…
(cos(359),sin(359)) = (0.999, -0.0175)
(cos(0),sin(0)) = (1, 0)
(cos(1),sin(1)) = (0.999, 0.0175)
Now if we add these vectors and divide by 3, we get
(V1+V2+V3)/3 = (2.998/3, 0) = (0.999, 0)
and then find the direction of the vector given.
tan^-1 of 0 = 0;
Therefore we have an Average of 0 Degree’s in vector direction.
The only problem is, when you have two completely opposing directions. Which for my implementation never happened, but it needed to be accounted for if things when haywire.
If have you a Direction of 180, and 0 then those cancel each other. and you have a null vector. This could create a problem for some implements, but just keep track of them, remove them from the average, before vectorizing, and then take the sample count down by 1.
So, there you have it, a use for trig finally on how to average Angles as a Direction.
I’ve been wracking my brain the last couple of months writing some nice C# Stuff. The biggest thing I wanted personally form the project was event-driven, no polling required data flow.
It seems easy enough, and using the datasets/views/list it’s not too hard to make everything “just happen”… but, then comes the head ache.
Custom Controls. I developed a really nice intensity / heat graph. I personally think the most important job of any good program is displaying all valuable data, quickly, and effectively without the use of a scroll bar.
But, how the hell do i get my data over to it my new control? Making the control poll a defined datatable wouldn’t work, because that’ breaks the rules i set myself. NO POLLING for data. let it come to you , otherwise in some way, you’re wasting cpu cycles. And this way, even if you are, it’s someone elses background code just working it’s own magic with events already defined.
So… here we are… we’ve got our own control.. now, you ask, how do we set up databinding?
easy. put a dataView on your control somewhere, and hide it.
then, put this at the top of your user control class..
[System.ComponentModel.ComplexBindingProperties(”DataSource”, “DataMember”)]
public partial class WidgetControl : UserControl
{
then simply add this stuff after the class declaration
public object DataSource
{
get { return dataGridView1.DataSource; }
set { dataGridView1.DataSource = value; }
}
public string DataMember
{
get { return dataGridView1.DataMember; }
set { dataGridView1.DataMember = value; }
}
}
and wa-la, you’ve got data, you’ve got events, you’ve got a life… not much like my own.
Ah, how easy it is…
here’s some quick msdn articles:
Walkthrough: Creating a User Control that Supports Complex Data Binding
Walkthrough: Creating a User Control that Supports Simple Data Binding
j.
I’ve been writing an extensive project in C# replacing an entire software library here at work.
One of my main pushes has been for dynamic user interfaces with “widgets”.
I write A LOT of different data visualization screens, and being able to contain them in a panel, and add them to any project like an OCX would be GREAT. The biggest problem i had was resizing the panel, and moving the panel around on the screen to allow a true dynamic panel.
It sounds stupid, but it was hard because i over thought it.
So, for those interested…
void pnlWidget_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right) { mnuContext.Show(new Point(e.X,e.Y + 75)); }
if (e.Button == MouseButtons.Left)
{
pnl_mousedown = true;
aCurrently.X = e.X;
aCurrently.Y = e.Y;
_mouseposX = aCurrently.X;
_mouseposY = aCurrently.Y;
pnlWidget.BorderStyle = BorderStyle.FixedSingle;
}
}
void pnlWidget_MouseMove(object sender, MouseEventArgs e)
{
if (pnl_mousedown == true && Locked == false)
{
this.Location = new Point(MousePosition.X - _mouseposX, MousePosition.Y - _mouseposY);
}
}
I can’t believe how stupid i was. I was writing it much harder before….
gah!
So, it’s been a while since I’ve written anything.
In brief, we bought a house, we painted everything we could (and couldn’t) reach. It’s been a long couple of weeks.
So, we finally moved in a little over a week ago. As any other person living in a technological age, we needed to get our cable hooked up. The previous owner of the house hacked some stuff together that resembles full-home coax. What I don’t understand, is the need to have 3 outlets in each bedroom? …
Anyway, the installer comes out, troops around a little bit, leaves the toilet set up, and gets some stuff working. The basement has all the connections… 9 rooms. 1 incoming connection. That’s a 9 way split. (Coax hub?) So, we get the living room working and the plasma has a good signal again… my wife finds some MTV drama to watch, and we continue to get the internet working in the office.
Now, I realize that there’s 9 outlets in the house. That’s sweet. There’s even one in the kitchen that we’ll probably never use. So, what does your installer do? Apparently he only connects to random outlets. We get the internet working upstairs, and then he calls in for the rx/tx/sma information… saying he wants to see all greens .. the answer back tx is in the red, reading 55. My whole life while writing serial communications, tx means transmission. Anyway, 55 is in the red. We wanted it in the green apparently. So, back to the basement he goes.
He tries a few things, with some ‘creative’ splices. The end result, tx in the red still, but at 52. He told me that this means my modem is putting out ” too much power”…. No idea. I noticed last night it’s a little doggy. And his reasoning why we couldn’t get that number any lower? Solar Wind. The #1 reason for anything going shady.
