Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calzim/only example cleanup #39

Closed
wants to merge 11 commits into from
Closed

Conversation

CalZim
Copy link

@CalZim CalZim commented Mar 12, 2020

No description provided.

fixed broken plots and naming conventions for all basic examples. Also fixed teacg repeat from arms examples. All examples should now run and plot data correctly.
mobile_io now has comments
fixed all but mobile control examples, mobile control only breaks after a pause and restart.
mobile device control is completely functional with no lock on rotation of the ee
created mobile_io_control example and fixed bugs in mobile_io
fixed up arm kit examples
fixed naming conventions and corrected impedence control setpoint
also added correct example log file
@rLinks234 rLinks234 self-requested a review March 15, 2020 16:11

# Plot using some handy helper functions
hebi.util.plot_logs(log, 'position', figure_spec=101)

log = hebi.util.load_log('{}/{}'.format(folder, name))
hebi.util.plot_logs(log, 'velocity', figure_spec=102)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call plot_logs with a string object too, so something like:

hebi.util.plot_logs('{}/{}'.format(folder, name), 'velocity', figure_spec=102)

but this is sufficient for now.

@@ -29,7 +29,7 @@
freq = freq_hz * 2.0 * pi # [rad / sec]
amp = pi * 0.25 # [rad] (45 degrees)

duration = 10.0 # [sec]
duration = 4 # [sec]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamtesch @CalZim Does anyone know why this changed to 4 seconds? It appears to be 10 seconds in the matlab example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure -- I think this might have just been a testing change. I'd prefer to keep it matching the MATLAB example for consistency.

@@ -29,7 +29,7 @@
freq = freq_hz * 2.0 * pi # [rad / sec]
amp = 1.0 # [rad] (45 degrees)

duration = 10.0 # [sec]
duration = 4 # [sec]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid spamming this PR with duplicate comments, see previous comment corresponding to 10->4 seconds in the examples... Not a big deal, just wondering why it was done

@@ -47,5 +48,30 @@

# Stop logging. `log_file` contains the contents of the file
log_file = group.stop_log()
hebi.util.plot_logs(log_file, 'position', figure_spec=101)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug in the Python API, which I believe has since been fixed, related to this (first plot_logs would work, but second would not, since the log file had been iterated through)... If it's fixed, we can revert the changes on the RHS here back to what it was previously.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this would be great to test and revert if possible :)

@@ -109,7 +111,13 @@ def execute_trajectory(group, model, trajectory, feedback):
group.get_next_feedback(reuse_fbk=feedback)
waypoints[:, 0] = feedback.position
waypoints[:, 1] = joint_targets[:, 0]
print("joint targets")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These print statements are extraneous and should be removed for the public facing examples.

current_button_state = [0, 0, 0, 0, 0, 0, 0, 0]
current_slider_state = [0, 0, 0, 0, 0, 0, 0, 0]

btn_states = ["", "", "", "", "", "", "", ""]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are class fields, not instance fields (i.e., they are static variables). This means that multiple instances of MobileIO will refer to a single instance of these variables, which I assume is not the intention here.

Move these definitions into __init__ to make them instance variables

return (self.current_button_state, self.current_slider_state)

# returns the change in button positions (currently breaks if called in same step as getState())
def getDiff(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, we have snake_case naming convention for our Python stuff (that is what is generally used in Python)... I'm not really opposed to camelCase (I prefer camel tbh), but it goes against what we generally use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as much as I dislike snake_case, I agree we should keep things consistent. I have a feeling this current name was influenced by porting this from C++.

# send a buzz to the mobile device (only works on iphones)
def sendVibrate(self):
self.cmd.effort = 1
return self.grp.send_command_with_acknowledgement(self.cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamtesch , should we do send_command_with_ack here, or just send_command ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm...I would probably stick with send_command, unless we are actually doing something with the feedback.

@CalZim , the biggest difference here is that under the covers, send_command_with_ack sends a message and then waits for a response. This means that this call is blocking, and if the return packet is dropped will block until the timeout is reached.

sendVibrate is something that is more likely to happen in a control loop as feedback, so the "fire and forget" style of send_command is probably more appropriate.

For functions such as setSnap which configure the interface as a "one time" action, these are much more appropriate to be done with a send_command_with_acknowledgement and have wrapping code in the app to check for success.

sleep(2.0)

family_name = "HEBI"
module_name = "Cal's iPhone"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to change this back to what other examples are using (for consistency)

orient = fbk[0].ar_orientation

r = R.from_quat(orient)
rot_mat = r.as_matrix()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a function (util.math_utils.quat2rot) to do this, and I'd prefer not to bring in a dependency like scipy (I forget if it's a different package than numpy or what...). However... it's not imported here (you need to add a directory to the PATH for Python to find it), so this warrants a discussion on the best way to resolve this dependency.

Copy link
Contributor

@iamtesch iamtesch Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CalZim -- I agree we should use our existing library functions where possible.
@rLinks234 -- I assume you mean the import is for the scipy/numpy, or is that for ours?

Ah -- I see your comment elsewhere, @rLinks234 . Yeah, I'm not a huge fan of having to alter the path; it there any better way to handle this?

])

plt.clf()
ax = plt.axes(projection="3d")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd assume this is potentially an expensive call which should be done once (outside of the loop), as opposed to each iteration

print("state: " + str(state))
counter += 1
if counter % 100 == 0:
print("counter: " + str(counter))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamtesch , should we leave all/some of these print statements in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so -- I think the counter was part of a debugging process? We should clean up the temporary/debug code where possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so...

@@ -111,106 +116,117 @@ def get_ik(xyz_target, rot_target, ik_seed):
# Start background logging
if enable_logging:
group.start_log(os.path.join(local_dir, 'logs'), mkdirs=True)
phone_group.start_log(os.path.join(local_dir, 'logs'), mkdirs=True)
#phone_group.start_log(os.path.join(local_dir, 'logs'), mkdirs=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want to log mobile IO feedback? Just wondering. If we don't (as implied by this line being commented out), then we should delete this commented out line.


first_run = True

print("check 2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these check X print statements were for debugging purposes... We should remove them before merging this in

# Send to robot
group.send_command(cmd)
#group.send_command(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be uncommented, right?

# Add the root folder of the repository to the search path for modules
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path = [root_path] + sys.path
# ------------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the hack necessary to add in the util package for stuff like the quat2rot functions.


# Mobile Device Setup
phone_family = 'HEBI'
phone_name = "Cal's iPhone"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to change this back

@@ -0,0 +1,320 @@
import hebi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is up with the ex_mobile_device_control_vX.py scheme here? It sounds like these were iterations to get the example working... If this is the case, we need to delete all but the one we want to keep

Copy link
Contributor

@rLinks234 rLinks234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great so far, but there are a few things which we need to change before we get this merged in. Thanks a lot for cleaning up my disastrous mess.

@rLinks234
Copy link
Contributor

So far, these changes are pertinent to get this merged in:

  • Remove extraneous print statements

  • Be consistent with the family, name values (e.g. Cal's phone --> Mobile IO or whatever)

  • Remove 3 of the 4 "iterations" of the mobile device example

  • Remove the hebilog files (These should not be in the repo). We can make sure to avoid any future .hebilog files creeping in to commits by adding a rule to the .gitignore

  • mobile_io.py file is in the examples. This should live somewhere else. Probably under util/input

@rLinks234 rLinks234 mentioned this pull request Mar 15, 2020
Copy link
Contributor

@cwbollinger cwbollinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some name changes to match convention, looks good overall!

Comment on lines +11 to +12
family_name = "Test Family"
module_names = ["J3_elbow", "J2_shoulder", "J1_base"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
family_name = "Test Family"
module_names = ["J3_elbow", "J2_shoulder", "J1_base"]
family_name = "Test Family"

Is there a reason the actuators in this list are backwards of normal convention? Typically we would order this [base, shoulder, elbow]

Comment on lines 11 to +12

family_name = "Test Family"
family_name = "Test Family"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

Comment on lines 11 to +12

family_name = "Test Family"
family_name = "Test Family"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace

Comment on lines 11 to +12

family_name = "Test Family"
family_name = "Test Family"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace


lookup = hebi.Lookup()

# Wait 2 seconds for the module list to populate
sleep(2.0)

family_name = "Test Family"
family_name = "Test Family"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace

enable_effort_comp = True

# Mobile Device Setup
phone_family = 'HEBI'
phone_name = 'Mobile IO'
phone_name = "Cal's iPhone"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set to default

arm_name = '6-DoF + gripper'
arm_family = 'Arm'
arm_name = '6-DoF'
arm_family = 'Example Arm'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this still be "Arm"?


# Mobile device setup
phone_family = 'HEBI'
phone_name = "Cal's iPhone"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixme


# Mobile device setup
phone_family = 'HEBI'
phone_name = "Phone Name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mobileIO

print_and_cr("When in playback mode, 'b6' resumes training, and 'b1' quits.")


m = mbio.MobileIO("HEBI", "Phone Name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mobileIO

@cwbollinger
Copy link
Contributor

Also, do we want to have logfiles included in the examples repo? It doesn't bother me either way, but I'm not sure what they represent since their names are timestamps. Maybe rename them if they are for specific examples?

t = 0

#t = 0
print("check 1")
Copy link
Contributor

@iamtesch iamtesch Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More debug printout and commented variables here and below...

@iamtesch
Copy link
Contributor

Also, do we want to have logfiles included in the examples repo? It doesn't bother me either way, but I'm not sure what they represent since their names are timestamps. Maybe rename them if they are for specific examples?

Unless the logfiles are part of an example in loading logfiles, we shouldn't have these in general

@cwbollinger cwbollinger deleted the calzim/only_example_cleanup branch November 6, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants