本文整理汇总了C#中IPacketReceiver.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# IPacketReceiver.Receive方法的具体用法?C# IPacketReceiver.Receive怎么用?C# IPacketReceiver.Receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPacketReceiver
的用法示例。
在下文中一共展示了IPacketReceiver.Receive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QuickModuleTutorial
//Now that we have some variables/references, we can start by declaring each one of them. So we do it here in the constructor
public QuickModuleTutorial()
{
//Lets start with the receiver
receiver = new SSLVisionReceiver(IPAddress.Parse("224.5.23.2"), 10002);
//The constructor to receiver needs the multicast IP and port on which the SSL Vision server is multicasting its packets,
//These can be found on SSL-Vision settings. Do make sure that your SSL-vision and network is correctly set up.
//You can test this by first connecting the receiver
receiver.Connect();
//Then making a call on receive
object packet = receiver.Receive();
if(packet==null)
throw new Exception("You messed up. Check your network and SSL Vision settings. ");
//Next, we have the sender
//Now we provide two kinds of senders, one for GRSim simulator, and another made for XBEE modules, initialize the one you need
sender = new GRSimSender(IPAddress.Loopback, 10020);
//Again, the IP address and port are the ones set up on GRSim. Verify them and that your network is good.
//You can test the sender too, first connect it
sender.Connect();
//Now create a RobotParameters object and set some random values i.e.
RobotParameters roboparams = new RobotParameters();
roboparams.IsBlue = true;
roboparams.Id = 1;
roboparams.XVelocity = 2;
//And send this packet through the sender
sender.Send(roboparams);
//If the robot specified in the robotId above doesn't show any movement, you messed up again.
//If you need the XBEE sender, then initialize it as
//sender = new XBeeSender("COM1");
//where COM1 is the port you connected the XBEE module to
//Ofcourse the XBEE sender needs the individual velocities to send them, so you need to set the angles between the wheels in each IRobotInfo's
//WheelAngles property before sending the packet
//Now comes the controllers, the one we provide is a PIDController, which is a modified implementation of PID by this guy Ron Beyer
//Firstly, you need to initialize the array of the controllers with length equal to the number of robots you have, or you like to move
//Lets say you are controlling six robots
controllers = new PIDController[6];
//next, initialize each controller with parameters of the robot
for (int i = 0; i < controllers.Length; i++)
{
controllers[i] = new PIDController(i, 2, 0, 0, 3025, -3025, 2, -2, 2, 0, 0, 2025, -2025, 2, -2, 5, 0, 0,
2*Math.PI, -2*Math.PI, Math.PI, -Math.PI);
//Yes its a hell lot of arguments and we did give out a much smaller constructor with default values, but thats the problem, they're default and may not suit
//your environment. Try to use this constructor. As for what the parameters are, I am not going to spill it out here, I've already given it in the constructor
//summary, go check there
}
//Now comes the module, which is completely your responsibility. Its the module that caused us to get into all this shit. Its the module that caused us to
//remodel our original program to have only one button named "Deep Shit"
//Yup you guessed it, the planner.
//We're not giving out the complete intelligence planner yet even though it contains some basic calculation functions,
//we do provide a manual controller, which can be used with a Joystick, so connect a joystick
//but for now, lets stick to some basics behavior, i.e. a test behavior defined in a dummy planner is to follow all the opponent robots
//Initialize the dummy planner as follows
planner = new DummyPlanner();
//Now if you have a working SSL-Vision receiver, you can also safely declare a referee receiver, its not currently being used but you'll need it
//when you write your own logic for obeying referee commands
//refereeReceiver = new SSLRefereeReceiver(IPAddress.Parse("224.5.23.3"), 10003);
//At this point, you have the absolute minimum things you need to run your system.
//Now you can make individual calls to each of the modules again and agin like
SSL_WrapperPacket receivedPacket = (SSL_WrapperPacket) receiver.Receive();
if (receivedPacket != null)
{
IRobotInfo[] plannedPoints = planner.PlanExclusive(receivedPacket);
if (plannedPoints != null)
{
for (int i = 0; i < plannedPoints.Length; i++)
{
plannedPoints[i] = controllers[i].ComputeExclusive(plannedPoints[i],
receivedPacket.detection.robots_blue[plannedPoints[i].Id]);
}
foreach(var pointWithVelocity in plannedPoints)
sender.Send(pointWithVelocity);
}
}
//and putting it in an infinite loop, which is pretty hideous if you ask me
// or you can automate the process with the rest of useful architecture we provided, for example;
//The data repository is a kind of utility we created to parse the incomming commands and store incomming/outgoing data in an organized way,
//its a good software practice so if you want to use it, you can initialize it too
dataRepository = new DataRepository(3, true);
//The repository also stores previous packets, which is useful for interpolation techniques. The size of history is given as the constructor argument
//The repository can be plugged in each of the above modules as follows. The modules will automatically read/write on repository
IDataSource sourceReference = (IDataSource) receiver;
sourceReference.Repository = dataRepository;
sourceReference = (IDataSource) sender;
sourceReference.Repository = dataRepository;
foreach (var controller in controllers)
{
sourceReference = (IDataSource) controller;
sourceReference.Repository = dataRepository;
}
sourceReference = (IDataSource) planner;
sourceReference.Repository = dataRepository;
//.........这里部分代码省略.........