auto_bus/src/bus.c

33 lines
644 B
C
Raw Normal View History

#include "bus.h"
2022-05-24 11:39:44 +08:00
#include "math.h"
bus_t *the_bus = NULL;
void RunBus(int direction)
{
2022-05-24 11:43:19 +08:00
if(direction == BUS_CLOCK_WISE)//顺时针
2022-05-24 11:39:44 +08:00
{
the_bus->distance++;
}
2022-05-24 11:43:19 +08:00
else if(direction == BUS_COUNTER_CLOCK_WISE)
2022-05-24 11:39:44 +08:00
{
the_bus->distance--;
}
2022-05-24 11:39:44 +08:00
}
int GetBusPosition()
{
int a,b;
a=the_bus->rail_node_pos->id;//指向站点的指针以及这个指针对应的站台id
b=a*(rails->last_node_distance)+abs(the_bus->distance);
return b;
}
int JudgeOnStation()
{
if(abs(the_bus->distance) == rails->last_node_distance)
{
2022-05-24 11:43:19 +08:00
return BUS_TRUE;
2022-05-24 11:39:44 +08:00
}
else
{
2022-05-24 11:43:19 +08:00
return BUS_FAlSE;
2022-05-24 11:39:44 +08:00
}
}