Week 18 - ngetachew/Portfolio GitHub Wiki
On the first day of the week, we were able to get the indeffector gears working. I researched online and found that if you decrease the "load" of the motor, it can provide more torque. I had no idea what this meant, or if it was even true, so I picked a random variable, the over current, and decreased it. It was originally at 6000, so I bumped it down to 5000. Strangely enough, it seemed to have a positive effect, as the gear stopped grinding as much. I tried decreasing it even more, to 4800, and it worked perfectly 10 out of 10 times. It seemed we had found a solution to our problem.
I then shifted my focus to the solenoid. The code had already been written to control it, but the magnet was too strong, and wasn't letting go of the game piece. I was testing out different PWM signals, and accidentally forgot to put the magnet back down, which resulted in the solenoid burning. I found out that it was getting 24 volts, so it cant be on for more than a minute.
This turned out to have less of an effect than I thought, but the magnet was still too strong. I tried cutting the game piece to make it shorter, but it still didn't work. My partner then had the genius idea of putting a washer in between the magnet and game piece, to weaken the attraction, and it worked!
The indeffector managed to cause more problems after this. We were testing its sensor when it suddenly sparked and burned a slush engine and a Pi. This set us back a few days, as we had to spend a few days reinstalling all the hardware. After this, the gear was too close to the sensor. Me and my partners were not able to figure it out, but a mentor was able to disable a register that was causing our problem. With this, the Delta Arm was complete!
I am now working on the bear element in the game. Using a module called networkx, I am able to provide the bear with the shortest path to the player and to the fish in order for it to provide an extra challenge. In 'easy' mode, the bear moves around randomly. In 'medium' mode, the bear moves the the fish and hovers around it, waiting for the player. In 'hard' mode, it calculates which is closer, the player or fish, moves towards them. Here is the code:
`def huntPlayer(self): global difficulty global turn #print('turn is ' + str(turn) + ', so moving twice will be ' + str(turn % 2 == 0)) # getting the bear actor bear = None player = None fish = None for b in self.children[0].children: if 'Bear' in b.source: bear = b if 'Player' in b.source: player = b if 'Goal' in b.source: fish = b shortest_path_from_bear_to_fish = nx.shortest_path(G, source=bear.number_as_int(), target=fish.number_as_int()) if difficulty == 'easy': bear_loc = bear.number_as_int() possible_locs = list((bear_loc + x) for x in [1, -1, 7, -7]) # Filter out invalid locations for loc in possible_locs: if loc not in G: possible_locs.remove(loc) bear.move(random.choice(possible_locs))
if difficulty == 'medium':
if len(shortest_path_from_bear_to_fish) > 1:
bear.move(shortest_path_from_bear_to_fish[0])
else:
diff = bear.number_as_int() - fish.number_as_int()
surrounding_fish_locs = self.getAdjacentTiles(fish)
surrounding_bear_locs = self.getAdjacentTiles(bear)#check
common_locations = list(set(surrounding_bear_locs).intersection(surrounding_fish_locs))
for loc in common_locations:
if str(loc) in fish.id:
common_locations.remove(loc)
bear.move(random.choice(common_locations))
if (difficulty == 'hard'):
shortest_path_from_bear_to_player = nx.shortest_path(G, source=bear.number_as_int(),
target=player.number_as_int())
if len(shortest_path_from_bear_to_fish) >= len(shortest_path_from_bear_to_player): #bear is closer to player)
bear.move(shortest_path_from_bear_to_player[0])
else: #bear is closer to the fish
if len(shortest_path_from_bear_to_player) > 1:
bear.move(shortest_path_from_bear_to_fish[0])
else:#bear is right next to fish, but won't eat it, so it moves towards the player instead
bear.move(shortest_path_from_bear_to_player[0])
`