Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How to smooth moving from serial Port in c# ?

$
0
0

Hi,
 
i try to create a Airplane attitude.
 
here is my serial port, that read from gyro.
 
actully its work but, my picture is slow moving and im not smooth moving.
 
how can i make it smooth??
 
First time i send Serial Like (Pitch Angle) in hex: 68 04 00 01 05 
with Timer = 80;
BaudRate = 9600;
 
i will recive Like : 68 07 00 81 00 04 62 EE
 
Also
68 04 00 04 08 for Pitch,Roll,Heading and this code that will read three Angle Make it More Slow !!!!!
 
How can i make rotation smooth ???


 

// OnPaint takes care of drawing all graphics to the screen automaticallyprotectedoverridevoidOnPaint(PaintEventArgs paintEvnt){// Calling the base class OnPaintbase.OnPaint(paintEvnt);// Clipping mask for Attitude Indicator
            paintEvnt.Graphics.Clip=newRegion(newRectangle(0,0,300,300));
            paintEvnt.Graphics.FillRegion(Brushes.Black, paintEvnt.Graphics.Clip);// Make sure lines are drawn smoothly
            paintEvnt.Graphics.SmoothingMode=SmoothingMode.HighQuality;// Create the graphics objectGraphics gfx = paintEvnt.Graphics;// Adjust and draw horizon imageRotateAndTranslate(paintEvnt, mybitmap1,RollAngle,0, ptBoule,(double)(4*PitchAngle), ptRotation,1);RotateAndTranslate2(paintEvnt, mybitmap3,YawAngle,RollAngle,0, ptHeading,(double)(4*PitchAngle), ptRotation,1);


            gfx.DrawImage(mybitmap2,0,0);// Draw bezel image
            gfx.DrawImage(mybitmap4,75,125);// Draw wings imageGraphics g =CreateGraphics();if(serialPort1.IsOpen==true){
                g.FillEllipse(Brushes.Green,20,350,20,20);}else

                g.FillEllipse(Brushes.Red,20,310,20,20);}privatevoid serialPort1_DataReceived(object sender,System.IO.Ports.SerialDataReceivedEventArgs e){int bytes = serialPort1.BytesToRead;byte[] buffer =newbyte[bytes];

             serialPort1.Read(buffer,0, bytes);if(bytes >7){if(buffer[4]==0)PitchAngle=Convert.ToDouble(buffer[5]);elsePitchAngle=-1.0*Convert.ToDouble(buffer[5]);Invalidate();}}

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>