Merge branch 'main' of gitlab.enterpriselab.ch:adis_team_gueti_roaster/adis_hs2022_team_4 into main

main
Simon Frei 4 years ago
commit 6649653a2f
  1. 4
      ADIS_Csharp/RobotClientWpf/ChallengeFactory.cs
  2. 6
      ADIS_Csharp/RobotClientWpf/NLog.config
  3. 2
      ADIS_Csharp/RobotClientWpf/Views/MainView.xaml
  4. 17
      ADIS_Csharp/RobotLib/Battery/DevBattery.cs
  5. 2
      ADIS_Csharp/RobotLib/Communication/MqttPublisherSubscriber.cs
  6. 32
      ADIS_Csharp/RobotLib/Robot.cs
  7. 9
      ADIS_Csharp/RobotLib/RobotTypes.cs
  8. 19
      ADIS_ESP32_Eclipse/main/robo_wrapper.c

@ -12,8 +12,8 @@ namespace RobotClientWpf
public ChallengeFactory() public ChallengeFactory()
{ {
this.PublisherSubscriber = MqttPublisherSubscriber.Instance; this.PublisherSubscriber = MqttPublisherSubscriber.Instance;
this.RobotStationary = new Robot(this.PublisherSubscriber); this.RobotStationary = new Robot(this.PublisherSubscriber, RobotTypes.Stationary);
this.RobotMobile = new Robot(this.PublisherSubscriber); this.RobotMobile = new Robot(this.PublisherSubscriber, RobotTypes.Mobile);
} }
} }
} }

@ -10,9 +10,15 @@
<target <target
xsi:type="CacheTarget" xsi:type="CacheTarget"
name="cache"/> name="cache"/>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/logs/logfile.txt"
keepFileOpen="true"
encoding="utf-8" />
</targets> </targets>
<rules> <rules>
<logger name="*" writeTo="cache" minlevel="Debug"/> <logger name="*" writeTo="cache" minlevel="Debug"/>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules> </rules>
</nlog> </nlog>

@ -23,7 +23,7 @@
</GroupBox> </GroupBox>
<GroupBox Header="Robot battery" Margin="10" HorizontalAlignment="Right" Width="180"> <GroupBox Header="Robot battery" Margin="10" HorizontalAlignment="Right" Width="180">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBox x:Name="tbRoboVoltage" Height="25" Width="150" FontSize="30" IsReadOnly="True" TextWrapping="NoWrap" HorizontalAlignment="Left"/> <TextBox x:Name="tbRoboVoltage" Height="25" Width="100" FontSize="15" IsReadOnly="True" TextWrapping="NoWrap" HorizontalAlignment="Left">NaN</TextBox>
<Label Content="V" Margin="10 0"/> <Label Content="V" Margin="10 0"/>
</StackPanel> </StackPanel>
</GroupBox> </GroupBox>

@ -31,11 +31,6 @@ namespace RobotLib.Battery
public DevBattery(IPublisherSubscriber com) : base(com, new List<string>() { TOPIC_ROBO_RESP_BATTERY }) { } public DevBattery(IPublisherSubscriber com) : base(com, new List<string>() { TOPIC_ROBO_RESP_BATTERY }) { }
public override void Refresh()
{
this.RequestBatteryVoltage();
}
public void RequestBatteryVoltage() public void RequestBatteryVoltage()
{ {
base.SendMessage(TOPIC_ROBO_REQ_BATTERY, true.ToString()); base.SendMessage(TOPIC_ROBO_REQ_BATTERY, true.ToString());
@ -45,14 +40,18 @@ namespace RobotLib.Battery
{ {
if (fromTopic == TOPIC_ROBO_RESP_BATTERY) if (fromTopic == TOPIC_ROBO_RESP_BATTERY)
{ {
var parsedVoltageString = GetValueFromMesage<string>("voltage", message); var parsedString = GetValueFromMesage<string>("voltage", message);
if (parsedVoltageString == null) parsedVoltageString = "?"; if (parsedString == null) parsedString = "?";
// example message = "Battery: 1.25 V" // example message = "Battery: 1.25 V"
var valueUnit = message.Trim().Split(' '); var valueUnit = parsedString.Trim().Split(' ');
string voltage = valueUnit[0].Trim(); string voltage = valueUnit[0].Trim();
float fVoltage = float.NaN;
this.Voltage = float.Parse(voltage); if(float.TryParse(voltage, out fVoltage))
{
this.Voltage = fVoltage;
}
} }
} }

@ -159,7 +159,7 @@ namespace RobotLib.Communication
} }
lock (clientLock) lock (clientLock)
{ {
var msgId = client.Publish(topic, Encoding.ASCII.GetBytes(message)); var msgId = client.Publish(topic, Encoding.ASCII.GetBytes(message), 0, false);
log.Trace($"Published to topic '{topic}'. MessageId = {msgId}"); log.Trace($"Published to topic '{topic}'. MessageId = {msgId}");
} }
} }

@ -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();
} }
} }
} }
} }

@ -0,0 +1,9 @@
namespace RobotLib
{
public enum RobotTypes
{
Undefined = 0,
Mobile = 1,
Stationary
}
}

@ -114,16 +114,8 @@ bool Robo_Wrapper_GetBatteryVoltage(unsigned char *voltage){
} }
static bool getValueOfStatusResponse(unsigned char* response, const unsigned char* key, unsigned char* value, size_t valueStringLen){ static bool getValueOfStatusResponse(unsigned char* response, const unsigned char* key, unsigned char* value, size_t valueStringLen){
int16_t pos = McuUtility_strFind(response, (unsigned char*)key);
unsigned char extractedString[50] = "";
if(pos == -1){ // error string not found = -1
ESP_LOGE(TAG, "Could not find key %s in response.", key);
return false;
}
unsigned char *p; unsigned char *p;
p = (unsigned char*)response + pos; p = (unsigned char*)response;
// skip first line (if the keyword would also appear in the headline, this is an issue) // skip first line (if the keyword would also appear in the headline, this is an issue)
while(*p!='\n'){ while(*p!='\n'){
@ -131,6 +123,14 @@ static bool getValueOfStatusResponse(unsigned char* response, const unsigned cha
} }
p+=1; // skip newline p+=1; // skip newline
// find key
int16_t pos = McuUtility_strFind(p, (unsigned char*)key);
if(pos == -1){ // error string not found = -1
ESP_LOGE(TAG, "Could not find key %s in response.", key);
return false;
}
p+=pos; // move pointer to found key
// skip until colon // skip until colon
while(true){ while(true){
if(*p==':'){ if(*p==':'){
@ -147,6 +147,7 @@ static bool getValueOfStatusResponse(unsigned char* response, const unsigned cha
} }
// extract value // extract value
unsigned char extractedString[50] = "";
uint8_t i = 0; uint8_t i = 0;
while(true){ while(true){
if(*p == '\n'){ if(*p == '\n'){

Loading…
Cancel
Save