Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yangliu28
GitHub Repository: yangliu28/swarm_formation_sim
Path: blob/master/line_formation_2_robot.py
104 views
1
# robot class for line formation 2 simulation
2
3
class LFRobot: # LF for line formation
4
def __init__(self, pos, vel, ori):
5
# pos, velocity, orientation for recording the physics
6
self.pos = list(pos) # convert to list
7
self.vel = vel # unsigned scalar
8
self.ori = ori # moving direction in the physical coordinates
9
# variables for configuring indivudual robot's formation process
10
self.status = 0 # key status for the formation, start with '0'
11
# '0' for being single, moving around, available for joining a group
12
# '1' for in a group, but not an indexed member, still on the way to the line
13
# '2' for in a group, indexed member, position is good
14
# '-1' for being single, moving around, and ignoring all connections
15
self.group_id = 0 # for status '1' and '2'
16
self.status_1_sub = 0 # sub status for status '1' robot
17
# '0' for forming the initial line segment
18
# '1' for merging into the line
19
self.status_1_1_des = [0,0] # destination for the merging robot
20
self.status_2_sequence = 0 # sequence along the line for status '2' robot
21
# index ranges from 0 to N-1
22
self.status_2_end = False # sub status deciding if robot is at larger index end
23
# False: not at the larger index end of the line
24
# True: at the larger index end, index should be N-1
25
self.status_2_avail1 = [True,True] # first availability for two sides to be merged
26
# first availability indicates if the distance is large enough for merging
27
# first value for small index side, second for large side
28
self.status_2_avail2 = [True,True] # second availability for two sides to be merged
29
# second availability indicates if a robot '1' is allowed to merge
30
# first value for the small index side, second for large side
31
self.key_neighbors = [-1, -1] # key neighbors to secure the group formation
32
# one member list for '1_0' robot, the other initial forming neighbor
33
# two member list for '1_1' and '2' robots
34
# first member is the robot on the smaller index side of the line
35
# second member is the robot on the larger index side of the line
36
# if no neighbor at one side, use -1 as a flag
37
self.status_n1_life = 0 # life time of status '-1', randomly generated
38
39
40
41
42