Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yangliu28
GitHub Repository: yangliu28/swarm_formation_sim
Path: blob/master/loop_formation_robot.py
104 views
1
# robot class for loop formation simulation
2
3
class LFRobot: # LF stands for loop formation
4
def __init__(self, pos, vel, ori):
5
# position, velocity, and orientation for the physics
6
self.pos = list(pos) # convert to list
7
self.vel = vel # unsigned scalar
8
self.ori = ori # moving direction
9
# variables for configuring individual robots's formation process
10
self.status = 0 # key status for the formation, start with '0'
11
# '0' for being single, moving around, available for grouping
12
# '1' for on the way to a formal group, temporary transition status
13
# '2' for being in a group, all members indexed, constantly adjusting position
14
# '-1' for being single, moving around, ignoring all connections
15
# see more details for substatuses in "loop_formation.py"
16
self.group_id = 0 # for status '1' and '2'
17
self.status_1_sub = 0 # substatus for status '1' robot
18
# '0' for forming the initial triangle
19
# '1' for merging into a loop
20
self.status_1_0_sub = 0 # substatus for status '1_0' robot
21
# '0' for forming the pair
22
# '1' for forming the triangle
23
self.status_1_0_1_des = [0,0] # destination for the triangle forming robots
24
self.status_1_1_des = [0,0] # destination for the merging robots
25
self.status_2_avail1 = True # first availability for this robot allowing merging
26
# indicating if the interior angle at this node is at good range
27
self.status_2_avail2 = [True,True] # second availability for two sides to be merged
28
# indicating if a robot is merging at one side, if yes, then availability is False
29
# first value for small index side, second for large side
30
self.key_neighbors = [-1,-1] # key neighbors to secure the group formation
31
# two members list for all '1' and '2' robots, except '1_0_0'
32
# first value is the robot on the small index side, second for large side
33
# if no neighbor at one side, value of '-1' will act as a flag
34
self.status_n1_life = 0 # life time of status '-1', randomly generated
35
36
37
38