Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b2a3b1b
[Update] Mutiple SA iterations + GUI Tool
aniketrajnish Jul 17, 2024
4178b61
Update README.md
aniketrajnish Jul 17, 2024
d8dd97c
Update README.md
aniketrajnish Jul 17, 2024
c588e6b
[Add] 25.57
aniketrajnish Jul 17, 2024
af9dafc
Merge branch 'main' of https://github.com/aniketrajnish/RoboCoOpt
aniketrajnish Jul 17, 2024
fb3320b
Delete pickle directory
aniketrajnish Jul 17, 2024
093a5ba
[Add] Tina's GA implementation
aniketrajnish Jul 17, 2024
0bd1450
Merge branch 'main' of https://github.com/aniketrajnish/RoboCoOpt
aniketrajnish Jul 17, 2024
f8ea969
[Add/Update] GA works!!
aniketrajnish Jul 19, 2024
ebdfb47
Update README.md
aniketrajnish Jul 19, 2024
f86ff79
[Update] Python Pkg Refactor
aniketrajnish Jul 20, 2024
695fed0
Merge branch 'main' of https://github.com/aniketrajnish/RoboCoOpt
aniketrajnish Jul 20, 2024
afc8e38
[Update] PKG structure
aniketrajnish Jul 20, 2024
26e21fe
[Update] .gitgnore & gif out changes
aniketrajnish Jul 20, 2024
a0b460c
[Update] Trainer Fixes
aniketrajnish Jul 20, 2024
2c73303
Delete tst.py
aniketrajnish Jul 20, 2024
bd21936
[Update] Push imgs gifs and temp pickles
aniketrajnish Jul 20, 2024
a68b7f9
Merge branch 'main' of https://github.com/aniketrajnish/RoboCoOpt
aniketrajnish Jul 20, 2024
e9ddf03
[Update] Trainer supports ga, cleaned up ga
aniketrajnish Jul 20, 2024
c93a007
[Update] Trainer functionality
aniketrajnish Jul 20, 2024
33e69b8
[Update] GUI updates
aniketrajnish Jul 21, 2024
ed3d7eb
[Update] Readme, lots of training
aniketrajnish Jul 21, 2024
2fc38fe
Update README.md
aniketrajnish Jul 21, 2024
d437b0a
Update README.md
aniketrajnish Jul 21, 2024
931221f
Update README.md
aniketrajnish Jul 21, 2024
d439d4e
Delete misc directory
aniketrajnish Jul 21, 2024
8cd46b1
[Add] MCTS implementation
aniketrajnish Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ __temp__
__temp__.tga
.idea
.venv
.pickle
.png
.png
/robo-env/
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/RoboCoOpt.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

123 changes: 55 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,59 @@

### Robot Co-optimization using planar linkage
The base code implements the planar linkage kinematics in `linkage.py`, and the linkage can be installed on a robot and simulate to test the robot performance using `linkage_physics.py`. Finally, we implemented a basic linkage optimizer using simulated annealing in `optimizer_anneal.py`.

#### Install

The code has been tested on Python 3.6 and 3.12.

To run the code, you first need to install Anaconda, which can be downloaded from https://docs.anaconda.com/anaconda/install/

Once Anaconda is installed, you can open the anaconda and type the following commands in order:

1. now, you can create your conda environment, named "box2d-py"

`conda create -n box2d-py`

2. remember every time you activate the environment, before you use it.

`conda activate box2d-py`

3. once you activate the environment for the first time, you need to install the following packages.

`conda install conda-forge::box2d-py` (box2d-py (https://github.com/pybox2d/pybox2d). Fortunately, you can install it via Anaconda.)

`pip install pygame`

`pip install numpy`

`pip install vapory`

4. run the Python scripts one by one

`python linkage.py`

`python optimizer_anneal.py`

`python linkage_physics.py`

### About linkage_physics.py

To run linkage_physics.py, you need the 'best.pickle' file that contains the design from optimizer_anneal.py. That said, before you run optimizer_anneal.py, you do not have it yet.

If you want to simply test the linkage_physics.py, instead, you can replace

`robot=create_robot('best.pickle', sep=5.)`

with

`link=Linkage.createSimple()`

`robot=create_robot(link, sep=5.) `

Once you run linkage_physics.py, you can control the robots via

press 'SPACE' to turn on/off simulation

press 'RCTRL' to turn on/off robot motor


### Installing Povray on Windows

On windows, the default povray does not work. We need a special version of povray that is independently compiled called MegaPov.
I have included a version of this MegaPov in the project, i.e., the megapov.rar. To enable povray on windows, unzip this folder to any directory.
Let's say you have a povray.exe located in "C:\Users\Admin\AppData\Roaming\POV-Ray\bin".
After this step, you need to add this to your system path as follows:
![alt text](https://github.com/dyingbrain/RoboCoOpt/blob/main/sys.png)

#### Note that you might need to restart the system to let the setting enabled.

### My Contribution

#### Day 0
- Cloned the repo, created a venv for the project, installed the required packages, solved various dependency issues.
- Since I'm not using conda, my resolution to the issues associated with `Box2D` was to install some additional dependencies like `swig` and `box2d-py` using `pip`.
- Ran `linkage.py`, `optimizer_anneal.py` and `linkage_physics.py` to verify the installation and the working of the code.
- Studied the codebase to understand the implementation of the planar linkage kinematics, the simulated annealing optimizer, and the linkage physics simulation.

#### Day 1
- To see the best possible results being generated by the optimizer for 1000 steps, I automated the process of running the optimizer and kept a track of the best results by updating the `.pickle` file if the current score is greater than the high score.
- The best fitness score I got after 8 iterations was `~10.77` after 28 iterations of the optimizer.
- I created a simple GUI around this functionality to keep track of all the results and the best result using `PyQt5`.

<p align="center">
<img src="https://github.com/user-attachments/assets/6f84339c-da97-4221-b358-d3ee2c68577a" alt="record">
</p>

https://github.com/user-attachments/assets/9985374c-505e-48f7-9b4a-3bfdfeb526aa

#### Day 2
- Let the tool run for the entire day, achieved a fitness score of `~25.5` using Simulated Anenaling over multiple iterations using the trainer.
- Implemented genetic algorithms by Tina Wu.

<p align="center">
<img src="https://github.com/user-attachments/assets/110c3e45-b22a-4aef-ac7d-98d572f29fd5" alt="record">
</p>

#### Day 3
- Fixed several bugs associated with genetic algo, improved upon the code design.
- Integrated `.pickle` export functionality to visualize the results in `pygame`.
- Current fitness score is in the ballpark of `2-5`
- Need to work on defining our own `crossover` and `mutation` implementation for genetic algorithms to function correctly.
- Dk why the wheels are suddenly so big with no change to the codebase 💀

<p align="center">
<img src="https://github.com/user-attachments/assets/ebd2197b-2055-4b4a-b5cd-c93a0d1dc76e" alt="record">
</p>

#### Day 4
- Implemented parallel processing for the genetic algorithm to speed up the process.
- Fixed the issue with the wheels being too big.
- Implemented the custom `crossover` and `mutation` functions to improve the results by the genetic algorithm.
- Fitness score of `~24.05` achieved after over 100 generations with a population size of 100 in each generation.

<p align="center">
<img src="https://github.com/user-attachments/assets/30ede664-16e4-45f1-bad2-3a47cdbfc204" alt="record">
</p>

#### Day 5
- Converted the project structure into that of python package.
- Extended the trainer gui to include the genetic algorithm functionality as well as accepting parameters for both algorithms.

<p align="center">
<img width="411" alt="image" src="https://github.com/user-attachments/assets/b2cc8722-350b-4bc7-849a-2a3558e9778b">
</p>

Now you can press "LSHIFT" in the window to have the povray render a nice image for you, an example is as follows:
![alt text](https://github.com/dyingbrain/RoboCoOpt/blob/main/frm.png)
Loading