Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / UDP Network Advice

Author
Message
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 30th Mar 2022 14:09
Hi All
Haven't been around for a long time. I need some help with UDP in a AGKS.

My Network and Device is working perfectly fine (Same Network/Same IP etc).
I can use Commands in a BAT file



This works fine

I can also send the command with PacketSender GUI and receive an OK message
See attached Message


In AppGameKit (This is the first time I try this, so maybe need to add something extra)



I get the error Failed to Create UDP listener

What do I miss.

Is there something else I need to do in AppGameKit before calling the createUDPlistener function

BTW. This is to control a DJI Tello EDU Drone

Thanks
Danie




Attachments

Login to view attachments
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 30th Mar 2022 14:49
Answer my own Question.
Got it working, But I don't get any message back. It is suppose to return "Ok" or "Error"

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 30th Mar 2022 19:53
I may not be understanding what you're trying to do, but it looks like you are sending the UDP packet outbound to the 50.21 address. So unless you are returning it back from that destination, you won't get it back. Additionally, even if it did get sent back, it probably wouldn't return fast enough to retrieve it using the GetUDPNetworkMessage command immediately after your send operation. Instead, you would need to continually check for incoming messages on your listening port until one arrives, then process it by getting the string with GetNetworkMessageString, like this:



In a local network setup, the packet would likely make the round trip in about 10-50ms. Another factor to consider is your receiver needs to handle the UDP packet in the format that AGK/S is sending it. So you're not going to just get a string with 'command' in it, you'll have some header content you'll need to deal with as well. As a result, your receiver needs to process the packet using AGK/S's UDP GetUDPNetworkMessage procedure in the same format your app is sending it. Then if your receiver is to return a reply, it also needs to send it back to your app in the same format for the command to work there as well.
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 31st Mar 2022 00:30
@SFSW

Quote: "I may not be understanding what you're trying to do, but it looks like you are sending the UDP packet outbound to the 50.21 address"

Yes, sending "strings" to the I outbound, and need to receive message back

It is to control more than one drone is a sequence (Drone Swarming)

Grade 12 Student for their final Engineering exam will do the drone swarming with music sequence.
I got it working using Bat files. They goal is to build a GUI to plot the drone movements and send commands accordingly.

The following Bat File explain (Using 3 drones)
command // Initialise the drones
takeoff // takeoff to 1 meter height
forward 50 // move forward 50cm
cw 180 // Turn Clockwise 180 degrees
back 50 // move back 50cm
land // land the drone

This work 100% as expected with DOS bat file. I need to do the same using AGKS.

According to the Tello SDK.

The IP addresses is the IP's of the drone connected to the tello-dev wifi.
The laptop controlling is also connected to the Tello-dev Wifi (same IP range)
It will either return "Ok" or "Error"

Packet sender is just a free utility to send UDP commands. I don't to "results" but the GUI do that. See above screen shots

Hope this make more sense.



Thanks in Advance
Danie
Zappo
Valued Member
19
Years of Service
User Offline
Joined: 27th Oct 2004
Location: In the post
Posted: 31st Mar 2022 12:08
I'm not sure I quite understand what you are trying to do either but I think SFSW got it right and you are expecting an immediate response from the receiver - which you won't get. Remember, UDP is a connectionless protocol so basically your messages are "fire and forget", i.e. the sender transmits the message and doesn't care if it gets to it's destination or not. It is a one-way system. Unlike TCP it doesn't get a confirmation message automatically to say the message was received or an error if it wasn't. If you want that, you either need to use TCP or set up both a transmitter and listener on both the sender and receiver for two way communication so one can reply to the other and confirm the receipt of messages.

I hope that makes sense.
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 31st Mar 2022 14:29
@Zappo

Quote: "I'm not sure I quite understand what you are trying to do either"


Let me try to explain again.
It is a DJI Tello Education Drone.
These drone can ONLY receive UDP messages.

For example. Using examples from the Batch file which is working

1. Send a command to\Initialize the drone... packetsender -u -a 10.105.221.20 8889 command
Now I need to wait for a "Ok" or "Error" return message
If no message within a few seconds, resend the command (The reason I use timeout /t 3" to wait 3 seconds (becauset I cant read the Return Messages in a Batch file.
Lets assume I receive an "Ok"
2. Send second command.... packetsender -u -a 10.105.221.20 8889 takeoff
Wait for an "Ok" to receive...
If The "Ok" message receive excecute the next Message
3. Move forward 100cm .... packetsender -u -a 10.105.221.20 8889 "forward 100"
Wait for an "Ok" to receive...
If The "Ok" message receive excecute the next Message etc etc etc

I use packetsender and it works and return results almost everytime.
Unfortunate the drones only support UDP

I understand how to send/receive, but I can't get it to work with AGKS
The "Drone" don't receive my packets send... So somewhere my code for sending is wrong. If I can get this working, then I can get the receive message

Example of my AGKS code



This is the Equivalent code to send the above messages using UDP in my batch file

packetsender -u -a 10.105.221.20 8889 command -- And it works

But I need to use AGKS to send UDP messages as we busy to do a GUI to control the drones (See Attached Screenshot)



Current I'm using this code, which is not only ugly, but the cmd screen popup with every run, and I cant get the return result message (But it works) AGKS need to replace this ....



Hope this make sense...

Danie











SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 31st Mar 2022 16:03 Edited at: 31st Mar 2022 16:12
@ DannyD,

Sounds like you may still be missing the points mentioned. It doesn't matter what you are trying to do with UDP, what matters is method and format. While AppGameKit can use the UDP protocol, it does so with its own format. Here is a review of requirements you'll need to consider:

- IIRC, AppGameKit includes a 4-byte header for its packets as a validation marker. For strings, there is also a length value included so any receiver knows how many characters to load. So you can't just send 'command' as a string by itself in a UDP packet -from- AGK. Your receiver must account for any header values and successive values structured by AppGameKit (header + sZ/string length + string) in the packet. If it doesn't, then it won't work until you read the data and parse it yourself on the receiving end and/or change your receiving code to handle the UDP packet sent by AppGameKit in the format it requires. That means if you're not running an AppGameKit app on the 'DJI Tello Education Drone' to receive the UDP packet sent by AppGameKit from your sender, your receiver probably doesn't know what to do with a packet it gets from AGK. Any string, such as 'command', will be received with garbled characters caused by header/length data even before the string is reached, so it won't be understood as a valid directive.

I think the first thing you need to do is use a packet monitor and look at the packet you are sending out from AGK. Compare that to what a packet looks like sent via command line and/or from your sending utility. At that point, you'll have a better understanding of what the differences are and what you need to do to account for those differences so that your receiver can parse and process any incoming UDP packet from AGK. Ultimately, if you want this to work, you're probably going to have to find a way to modify the drone's receiving system to accommodate AGK's UDP packet format.

Likewise, if your receiver sends back a UDP packet for confirmation (the 'Ok' or 'Error' message string), you'll need to modify that sending system to structure a packet in AGK's format. Otherwise, you'll run into the same problem on the AGK-side of things in that AGK/S also won't know what to do with a packet that doesn't include its formatting/values.
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 1st Apr 2022 00:05
@SFSW

Okay, that makes more sense why it doesn't work to just receive/send just a "normal" string.

Anyway, I use Basic 4Android last night and got it working. So we will switch from APPGAMEKIT to Basic4Android for future use in our STEAM Education Development Program. Might be a better option, because the drones can't be modified.

Another failed attempt to implement AGKS in our projects...

Thanks
Danie

Login to post a reply

Server time is: 2024-04-24 04:01:56
Your offset time is: 2024-04-24 04:01:56