mithi/hexapod-robot-simulator

Hexapod object doesn't check whether the angles are within range as set in `settings.py`

Closed this issue · 8 comments

mithi commented

Should it? The IK solver checks it, and the widget slider constraints the angles as well.

@mithi I would like to help - but could you be a little more clearer what it is that needs to be changed and where exactly.

Right now, I feel like I have to guess a little bit.....OR I just don't understand!

mithi commented

@mithi I would like to help - but could you be a little more clearer what it is that needs to be changed and where exactly.

Right now, I feel like I have to guess a little bit.....OR I just don't understand!

Thanks for your interesting in making helping with this project!

What I meant was, to check it the poses are within range before updating the VirtualHexapod

def update(self, poses, assume_ground_targets=True):

You can make a helper function ie

def poses_within_range(poses):

which can be called

if not poses_within_range(poses):
    raise Exception(f"❗Some of the values in {poses} are not within range")

or something like that.

Hope that helps!

Don't forget to test your code to make sure you didn't break anything! Enjoy!

@mithi i was having trouble logging into git for the past days, but seeing your note now.

thanks, for the update, i think i get it and can get to work.

@mithi a couple issues here:

  1. self.legs[i].change_pose(pose["coxia"], pose["femur"], pose["tibia"]) is updating the dimensions of the robot NOT the leg pattern angles. (models.py - line 127)
  2. the default dimensions are no assigned/declared in settings.py
  3. def update(self, poses, assume_ground_targets=True): is NOT updating leg pattern angles as implied by this issue.

i am not asking to be spoon fed, but it looks like there is a bit of contradiction, if you can clarify when you get a moment.

thanks!

mithi commented

Hi @markkulube ,

I'm sorry but I don't think you understand how the program works. Your first and third point is incorrect.

First of all, I'm sorry that the naming convention is confusing you. I understand where the confusion is coming from. This is because coxia, femur, and tibia names are referring to the lengths / dimensions of the hexapod in the dimensions dictionary. But coxia , femur, and tibia in the poses and pattern poses dictionary are referring to the angles made by each pose.

You will be able to infer this information by looking at the following files:

The coxia, femur, and tibia, here are referring to lengths of the hexapod

BASE_DIMENSIONS = {
"front": 100,
"side": 100,
"middle": 100,
"coxia": 100,
"femur": 100,
"tibia": 100,
}

The coxia, femur, and tibia is referring to angles here in degrees

# pose = {
# LEG_ID: {
# 'name': LEG_NAME,
# 'id': LEG_ID
# 'coxia': ALPHA,
# 'femur': BETA,
# 'tibia': GAMMA}
# }
# ...
# }
HEXAPOD_POSE = {
0: {"coxia": 0, "femur": 0, "tibia": 0, "name": "right-middle", "id": 0},
1: {"coxia": 0, "femur": 0, "tibia": 0, "name": "right-front", "id": 1},
2: {"coxia": 0, "femur": 0, "tibia": 0, "name": "left-front", "id": 2},
3: {"coxia": 0, "femur": 0, "tibia": 0, "name": "left-middle", "id": 3},
4: {"coxia": 0, "femur": 0, "tibia": 0, "name": "left-back", "id": 4},
5: {"coxia": 0, "femur": 0, "tibia": 0, "name": "right-back", "id": 5},
}

If you look at the pattern pose page

@app.callback(output_parameter, input_parameters)
def update_poses_alpha_beta_gamma(alpha, beta, gamma):
return json.dumps(helpers.make_pose(alpha, beta, gamma))

You will see it invokes the make_pose function, which assigns the alpha, beta and gamma to each leg respectively.

def make_pose(alpha, beta, gamma, poses=NEW_POSES):
for k in poses.keys():
poses[k] = {
"id": k,
"name": NAMES_LEG[k],
"coxia": alpha,
"femur": beta,
"tibia": gamma,
}
return poses

Which means it will be

pose = { 
     0: {"coxia": alpha, "femur": beta, "tibia": gamma, "name": "right-middle", "id": 0}, 
     1: {"coxia": alpha, "femur": beta, "tibia": gamma, "name": "right-front", "id": 1}, 
     2: {"coxia": alpha, "femur": beta, "tibia": gamma, "name": "left-front", "id": 2}, 
     3: {"coxia": alpha, "femur": beta, "tibia": gamma, "name": "left-middle", "id": 3}, 
     4: {"coxia": alpha, "femur": beta, "tibia": gamma, "name": "left-back", "id": 4}, 
     5: {"coxia": alpha, "femur": beta, "tibia": gamma, "name": "right-back", "id": 5}, 
 } 

If you look at the kinematics and pattern pages of the app, you will find the following lines

hexapod = VirtualHexapod(dimensions)
try:
hexapod.update(poses, assume_ground_targets=False)

hexapod = VirtualHexapod(dimensions)
try:
hexapod.update(poses)

Which is practically identical.

It gives the pose, (which is a dictionary which contains the 18 poses, 3 angles for each of the 6 legs, 18 total) to the update method to update the points of the hexapod.

You will also see it in this function which is a function that the inverse kinematics page calls.

new_hexapod = VirtualHexapod(dimensions)
new_hexapod.update(poses)

I'm sorry that all of this are confusing to you. This is my first-time creating an first-timers-only issue, I will be removing this the first-timers-only tag in this issue and closing this issue, as it seems that it's not as straightforward as I thought it would be given the non-trivial size of the project; and taking into the account that this project has very little documentation.

@mithi THANK YOU for the very detailed explanation. I think with this i should be able to navigate better through the project.

I am sure it goes without saying, that variable names should be used consistently even if appearing in different modules/functions/classes etc.

Removing thw tags is reasonable, while this really a simple issue, it demands a quite a bit more than what is normally reserved for first-timers-only / good-first-issue tags.

Such issues are really meant to acquaint the first time with forking, cloning, and the PR sequence. For instance renaming coxia, femur, and tibia to distinguish between where said variables/keys refer angle and length/dimension. Obviously you would need to be explicit as to where the renaming takes place that is to the very line.

That being said, you've, put in a lot of effort in clarifying here, so I in want to see this issue through.

Thanks again!

mithi commented

@mithi THANK YOU for the very detailed explanation. I think with this i should be able to navigate better through the project..

That being said, you've, put in a lot of effort in clarifying here, so I in want to see this issue through.

Thanks again!

Enjoy! ❤️

@mithi Thanks. PS: I am also being stretched from my coop/internship. This still remains on my todo list, but please bear with me.