C#如何将Uint从my Mainwindow.xaml.cs导入Program.cs
为了更好地理解,我正在开发一个程序,可以跟踪我的手臂和腿的角度(使用kinect),并将其发送给NXT Mindstorm机器人。 我对VisualStudio和C#还很陌生,但我设法让程序实时跟踪我的身体和角度。 我现在的问题是,我无法实时获取机器人的角度。我试图在扫描角度后直接发送数据,但这导致了一个错误,导致了那里的循环。所以我添加了一个带有mindsquals.dll(Mindstorms的Libary)的控制台文件,并希望在那里运行它 我现在的问题是,当Mainwindow.xaml.cs运行时,是否可以将角度实时发送到控制台应用程序 这是我的程序的一部分,其中的角度是建立。需要转换原因brick.MotorB.Run仅适用于UintC#如何将Uint从my Mainwindow.xaml.cs导入Program.cs,c#,wpf,xaml,C#,Wpf,Xaml,为了更好地理解,我正在开发一个程序,可以跟踪我的手臂和腿的角度(使用kinect),并将其发送给NXT Mindstorm机器人。 我对VisualStudio和C#还很陌生,但我设法让程序实时跟踪我的身体和角度。 我现在的问题是,我无法实时获取机器人的角度。我试图在扫描角度后直接发送数据,但这导致了一个错误,导致了那里的循环。所以我添加了一个带有mindsquals.dll(Mindstorms的Libary)的控制台文件,并希望在那里运行它 我现在的问题是,当Mainwindow.xaml.
double AngleRightArm = Vector3D.AngleBetween(ShoulderElbowR, NewPShoulderR); //Angle Right Arm
double AngleLeftArm = Vector3D.AngleBetween(ShoulderElbowL, NewPShoulderL); //Angle Left Arm
UInt16 RobotArmR = Convert.ToUInt16(AngleRightArm);
UInt16 RobotArmL = Convert.ToUInt16(AngleLeftArm);
这是我的控制台应用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NKH.MindSqualls;
using WpfApplication1;
namespace RoboterMove
{
class Program
{
static void Main(string[] args)
{
// Create a NXT brick,
// and use Bluetooth on COM40 to communicate with it.
NxtBrick brick = new NxtBrick(NxtCommLinkType.USB, 0);
// Attach motors to port B and C on the NXT.
brick.MotorB = new NxtMotor();
brick.MotorC = new NxtMotor();
// Connect to the NXT.
brick.Connect();
// Run them at 75% power, for a 3600 degree run.
brick.MotorB.Run(75, RobotArmR);
brick.MotorC.Run(75, RobotArmL);
// Disconnect from the NXT.
brick.Disconnect();
}
}
}
由于两个应用程序都在同一个项目中,所以应该有一种方法来实现这一点,但我尝试的所有方法都没有真正起作用,或者导致应用程序崩溃
谢谢:)将try-catch块添加到代码中,分析异常并自行更正,或者将其添加到问题中:
static void Main(string[] args)
{
try{
// Create a NXT brick,
// and use Bluetooth on COM40 to communicate with it.
NxtBrick brick = new NxtBrick(NxtCommLinkType.USB, 0);
// Attach motors to port B and C on the NXT.
brick.MotorB = new NxtMotor();
brick.MotorC = new NxtMotor();
// Connect to the NXT.
brick.Connect();
// Run them at 75% power, for a 3600 degree run.
brick.MotorB.Run(75, RobotArmR);
brick.MotorC.Run(75, RobotArmL);
// Disconnect from the NXT.
brick.Disconnect();
}
catch(Exception ex){}
}
希望这可能会有所帮助。最好将其转移到WPF项目中,除非需要控制台应用程序来处理数据采集。首先尝试了另一种答案,但最后我在主程序中使用了另一种方法,效果很好。谢谢你的帮助!