-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do an example of a full serializable struct
- Loading branch information
Showing
14 changed files
with
391 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,19 @@ | ||
using Hal; | ||
using NetworkTables; | ||
using NetworkTables.Natives; | ||
using System; | ||
using System.Linq; | ||
using WPILib; | ||
using System; | ||
using System.Text.Json; | ||
using UnitsNet.NumberExtensions.NumberToAngle; | ||
using WPIMath.Geometry; | ||
|
||
namespace desktopDev | ||
{ | ||
public class Robot : TimedRobot | ||
{ | ||
private TimeSpan lastTime = Timer.FPGATimestamp; | ||
readonly double[] buffer = new double[50]; | ||
int idx = 0; | ||
|
||
private readonly int pwm = Hal.PWMLowLevel.InitializePort(HALLowLevel.GetPort(42)); | ||
|
||
private readonly int can = CANAPILowLevel.Initialize(CANManufacturer.kTeamUse, 1, CANDeviceType.kMiscellaneous); | ||
|
||
|
||
|
||
public override unsafe void RobotPeriodic() | ||
{ | ||
int idxLocal = idx; | ||
CANAPILowLevel.WritePacket(can, new Span<byte>(&idxLocal, 4), 42); | ||
|
||
var current = Timer.FPGATimestamp; | ||
var delta = current - lastTime; | ||
lastTime = current; | ||
buffer[idx] = delta.TotalMilliseconds; | ||
idx++; | ||
if (idx == 50) | ||
{ | ||
Console.WriteLine(buffer.Average()); | ||
idx = 0; | ||
} | ||
base.RobotPeriodic(); | ||
} | ||
} | ||
namespace DesktopDev; | ||
|
||
class Program | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Rotation2d rot = new(5.Radians()); | ||
string serialized = JsonSerializer.Serialize(rot); | ||
Console.WriteLine(serialized); | ||
|
||
public class HolderMethod | ||
{ | ||
public void doThing() | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class Container | ||
{ | ||
public Action holder; | ||
|
||
public Container(HolderMethod holder) | ||
{ | ||
this.holder = holder.doThing; | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
NtCore.Initialize(); | ||
NetworkTableInstance instance = NetworkTableInstance.Default; | ||
GC.KeepAlive(instance); | ||
//var i = SendableRegistry.Instance; | ||
|
||
//var map = new ConditionalWeakTable<HolderMethod, Container>(); | ||
|
||
//var holder = new HolderMethod(); | ||
//map.Add(holder, new Container(holder)); | ||
////holder = null; | ||
|
||
////while (map.Any()) | ||
////{ | ||
//// //Console.WriteLine(map.Count()); | ||
//// GC.Collect(); | ||
////} | ||
//RobotBase.StartRobot<Robot>(); | ||
} | ||
Rotation2d r = JsonSerializer.Deserialize<Rotation2d>(serialized); | ||
Console.WriteLine(r.Angle.Radians); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.