为了更好地理解,我正在开发一个程序,可以跟踪我的手臂和腿的角度(使用kinect)并将其发送到NXT Mindstorm Robot。 我是Visual Studio和C#的新手,但我设法让程序实时跟踪我的身体和角度。 我现在的问题是,我无法实时获取机器人的角度。我试图在扫描角度后直接发送数据,但这导致了循环的错误原因。所以我添加了MindSqualls.dll(Libary for Mindstorms)的控制台文件,并希望在那里运行它。
我现在的问题是,当Mainwindow.xaml.cs正在运行时,是否可以实时向控制台应用程序发送角度。
这是构建角度的程序的一部分。需要转换原因brick.MotorB.Run仅适用于Uint。
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();
}
}
}
由于两个应用程序都在同一个项目中,应该有办法让这项工作,但我尝试的一切都没有真正起作用或使应用程序崩溃。
谢谢:)
答案 0 :(得分:0)
将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){}
}
希望这可能会有所帮助。