|
|
|
@ -2,26 +2,43 @@ |
|
|
|
using RobotLib.SplitFlap; |
|
|
|
using RobotLib.SplitFlap; |
|
|
|
using RobotLib.Movement; |
|
|
|
using RobotLib.Movement; |
|
|
|
using RobotLib.Battery; |
|
|
|
using RobotLib.Battery; |
|
|
|
using System.Threading; |
|
|
|
using System.Timers; |
|
|
|
|
|
|
|
|
|
|
|
namespace RobotLib |
|
|
|
namespace RobotLib |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class Robot |
|
|
|
public class Robot |
|
|
|
{ |
|
|
|
{ |
|
|
|
public Robot(IPublisherSubscriber com) |
|
|
|
public Robot(IPublisherSubscriber com, RobotTypes type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Com = com; |
|
|
|
Com = com; |
|
|
|
|
|
|
|
Type = type; |
|
|
|
|
|
|
|
if(type == RobotTypes.Undefined) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new System.ArgumentException("Undefined robot type, must define type!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(type == RobotTypes.Mobile) |
|
|
|
|
|
|
|
{ |
|
|
|
//Buzzer = new DevBuzzer(Com); |
|
|
|
//Buzzer = new DevBuzzer(Com); |
|
|
|
Battery = new DevBattery(Com); |
|
|
|
Battery = new DevBattery(Com); |
|
|
|
SplitFlap = new DevSplitFlap(com); |
|
|
|
|
|
|
|
LineSensor = new DevLineSensor(com); |
|
|
|
LineSensor = new DevLineSensor(com); |
|
|
|
Movement = new DevMovement(com); |
|
|
|
Movement = new DevMovement(com); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if(type == RobotTypes.Stationary) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
SplitFlap = new DevSplitFlap(com); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Timer timer = new Timer(TimerCallback); |
|
|
|
Timer timer = new Timer |
|
|
|
timer.Change(2000, 10000); |
|
|
|
{ |
|
|
|
|
|
|
|
Interval = 10000 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
timer.Enabled= true; |
|
|
|
|
|
|
|
timer.Elapsed += Timer_Elapsed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IPublisherSubscriber Com { get; } |
|
|
|
public IPublisherSubscriber Com { get; } |
|
|
|
|
|
|
|
public RobotTypes Type { get; } |
|
|
|
|
|
|
|
|
|
|
|
//public DevBuzzer Buzzer { get; } |
|
|
|
//public DevBuzzer Buzzer { get; } |
|
|
|
public DevBattery Battery { get; } |
|
|
|
public DevBattery Battery { get; } |
|
|
|
@ -39,13 +56,12 @@ namespace RobotLib |
|
|
|
//Com.Disconnect(); |
|
|
|
//Com.Disconnect(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void TimerCallback(object state) |
|
|
|
private void Timer_Elapsed(object sender, ElapsedEventArgs e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (Com.IsConnected) |
|
|
|
if (Com.IsConnected) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Battery.Refresh(); |
|
|
|
Battery?.RequestBatteryVoltage(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |