initial ESP32 tracker support

This commit is contained in:
Pascal Serrarens 2025-04-09 09:06:05 +02:00
parent 64864afcb4
commit e51159bd1b
5 changed files with 25 additions and 22 deletions

View File

@ -9,7 +9,7 @@ namespace RoboidControl {
/// <summary>
/// A participant is used for communcation between things
/// </summary>
public class LocalParticipant : Participant {
public class ParticipantUDP : Participant {
public byte[] buffer = new byte[1024];
public ulong publishInterval = 3000; // = 3 seconds
@ -26,7 +26,7 @@ namespace RoboidControl {
/// <summary>
/// Create a porticiapnt
/// </summary>
public LocalParticipant() {
public ParticipantUDP() {
//senders.Add(this);
}
@ -34,7 +34,7 @@ namespace RoboidControl {
/// Create a participant with the give UDP port
/// </summary>
/// <param name="port">The port number on which to communicate</param>
public LocalParticipant(int port) : this() {
public ParticipantUDP(int port) : this() {
this.port = port;
}
@ -43,7 +43,7 @@ namespace RoboidControl {
/// </summary>
/// <param name="ipAddress">The ip address of the site server</param>
/// <param name="port">The port number of the site server</param>
public LocalParticipant(string ipAddress = "0.0.0.0", int port = 7681) : this() {
public ParticipantUDP(string ipAddress = "0.0.0.0", int port = 7681) : this() {
this.ipAddress = ipAddress;
this.port = port;
@ -61,15 +61,15 @@ namespace RoboidControl {
/// </summary>
/// <param name="udpClient">UDP client to use for communication</param>
/// <param name="port">The port number on which to communicate</param>
public LocalParticipant(UdpClient udpClient, int port) : this() {
public ParticipantUDP(UdpClient udpClient, int port) : this() {
this.udpClient = udpClient;
this.port = port;
}
private static LocalParticipant isolatedParticipant = null;
public static LocalParticipant Isolated() {
private static ParticipantUDP isolatedParticipant = null;
public static ParticipantUDP Isolated() {
if (isolatedParticipant == null)
isolatedParticipant = new LocalParticipant(0);
isolatedParticipant = new ParticipantUDP(0);
return isolatedParticipant;
}
@ -182,13 +182,13 @@ namespace RoboidControl {
return true;
IPEndPoint participantEndpoint = new IPEndPoint(IPAddress.Parse(owner.ipAddress), owner.port);
// Console.WriteLine($"msg to {participantEndpoint.Address.ToString()} {participantEndpoint.Port}");
Console.WriteLine($"msg to {participantEndpoint.Address.ToString()} {participantEndpoint.Port}");
this.udpClient?.Send(this.buffer, bufferSize, participantEndpoint);
return true;
}
public void PublishThingInfo(Thing thing) {
//Console.WriteLine("Publish thing info");
Console.WriteLine("Publish thing info");
this.Publish(new ThingMsg(this.networkId, thing));
this.Publish(new NameMsg(this.networkId, thing));
this.Publish(new ModelUrlMsg(this.networkId, thing));
@ -275,10 +275,12 @@ namespace RoboidControl {
#region Process
protected virtual void Process(Participant sender, ParticipantMsg msg) { }
protected virtual void Process(Participant sender, ParticipantMsg msg) {
Console.WriteLine($"{this.name} Process participant {msg.networkId}");
}
protected virtual void Process(Participant sender, NetworkIdMsg msg) {
Console.WriteLine($"{this.name} receive network id {this.networkId} {msg.networkId}");
Console.WriteLine($"{this.name} Process network id {this.networkId} {msg.networkId}");
if (this.networkId != msg.networkId) {
this.networkId = msg.networkId;
foreach (Thing thing in this.things) //Thing.GetAllThings())
@ -289,7 +291,7 @@ namespace RoboidControl {
protected virtual void Process(Participant sender, InvestigateMsg msg) { }
protected virtual void Process(Participant sender, ThingMsg msg) {
//Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]");
Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]");
}
protected virtual void Process(Participant sender, NameMsg msg) {

View File

@ -7,7 +7,7 @@ namespace RoboidControl {
/// <summary>
/// A site server is a participant which provides a shared simulated environment
/// </summary>
public class SiteServer : LocalParticipant {
public class SiteServer : ParticipantUDP {
public SiteServer(int port = 7681) : this("0.0.0.0", port) { }
@ -42,11 +42,12 @@ namespace RoboidControl {
public override void Publish() {
}
protected override void Process(Participant remoteParticipant, ParticipantMsg msg) {
if (msg.networkId == 0) {
Console.WriteLine($"{this.name} received New Participant -> {remoteParticipant.networkId}");
this.Send(remoteParticipant, new NetworkIdMsg(remoteParticipant.networkId));
}
protected override void Process(Participant sender, ParticipantMsg msg) {
base.Process(sender, msg);
//if (msg.networkId == 0) {
Console.WriteLine($"{this.name} received New Participant -> {sender.networkId}");
this.Send(sender, new NetworkIdMsg(sender.networkId));
//}
}
protected override void Process(Participant sender, NetworkIdMsg msg) { }

View File

@ -65,7 +65,7 @@ namespace RoboidControl {
/// Create a new thing without communication abilities
/// </summary>
/// <param name="thingType">The type of thing</param>
public Thing(byte thingType = (byte)Type.Undetermined, bool invokeEvent = true) : this(LocalParticipant.Isolated(), thingType, invokeEvent) {
public Thing(byte thingType = (byte)Type.Undetermined, bool invokeEvent = true) : this(ParticipantUDP.Isolated(), thingType, invokeEvent) {
}
/// <summary>

View File

@ -8,7 +8,7 @@ namespace RoboidControl {
public DifferentialDrive() { }
/// @brief Create a differential drive with networking support
/// @param participant The local participant
public DifferentialDrive(LocalParticipant participant) : base(participant, Type.Undetermined) { }
public DifferentialDrive(ParticipantUDP participant) : base(participant, Type.Undetermined) { }
/// @brief Configures the dimensions of the drive
/// @param wheelDiameter The diameter of the wheels in meters

View File

@ -26,7 +26,7 @@ namespace RoboidControl {
public TouchSensor(Thing parent) : base(parent) { }
public LocalParticipant thisParticipant;
public ParticipantUDP thisParticipant;
/// <summary>
/// Value which is true when the sensor is touching something, false otherwise