You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
using RobotLib.Communication;
|
|
using RobotLib.SplitFlap;
|
|
using RobotLib.Movement;
|
|
using RobotLib.Battery;
|
|
using System.Timers;
|
|
using RobotLib.Status;
|
|
|
|
namespace RobotLib
|
|
{
|
|
public class Robot
|
|
{
|
|
public IPublisherSubscriber Com { get; }
|
|
public RobotMode Mode { get; }
|
|
|
|
//public DevBuzzer Buzzer { get; }
|
|
public DevBattery Battery { get; }
|
|
public DevSplitFlap SplitFlap { get; }
|
|
public DevMovement Movement { get; }
|
|
public DevLineSensor LineSensor { get; }
|
|
public DevStatus Status { get; }
|
|
|
|
public Robot(IPublisherSubscriber com, RobotMode mode)
|
|
{
|
|
Com = com;
|
|
Mode = mode;
|
|
if(mode == RobotMode.Undefined)
|
|
{
|
|
throw new System.ArgumentException("Undefined robot mode, must define mode!");
|
|
}
|
|
|
|
// battery is applicable for both modes
|
|
Battery = new DevBattery(Com, mode);
|
|
|
|
if(mode == RobotMode.Mobile)
|
|
{
|
|
//Buzzer = new DevBuzzer(Com);
|
|
LineSensor = new DevLineSensor(com);
|
|
Movement = new DevMovement(com);
|
|
Status = new DevStatus(com);
|
|
}
|
|
else if(mode == RobotMode.Stationary)
|
|
{
|
|
SplitFlap = new DevSplitFlap(com);
|
|
}
|
|
|
|
Timer timer = new Timer
|
|
{
|
|
Interval = 1000
|
|
};
|
|
timer.Enabled= true;
|
|
timer.Elapsed += Timer_Elapsed;
|
|
}
|
|
|
|
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
|
{
|
|
if (Com.IsConnected)
|
|
{
|
|
Battery?.UpdateLastResponse();
|
|
//Battery?.RequestBatteryVoltage(); // is automatically sent by robot
|
|
}
|
|
}
|
|
}
|
|
} |