bergsoe avatar bergsoe committed e3a7bf6

New [get_frame_name] function.

Comments (0)

Files changed (4)

c_robwork/papl_robwork.cpp

     }
 }
 
+int robwork_getFrameName(
+    const RW_Frame* frame, char* result, int size)
+{
+    const std::string& name = frame->frame->getName();
+    const int len = (int)name.size();
+
+    if (size == len) {
+        std::copy(name.begin(), name.end(), result);
+    }
+
+    return len;
+}
+
 /*----------------------------------------------------------------------*
   Collision detection
  *----------------------------------------------------------------------*/

c_robwork/papl_robwork.h

 extern int robwork_gripFrame(
     RW_Frame* item, RW_Frame* gripper, RW_State* state);
 
+extern int robwork_getFrameName(
+    const RW_Frame* frame, char* result, int size);
+/* The length of the name is returned. The name is written to 'result' if and
+   only if 'size' equals the length of the name.
+*/
+
 /*----------------------------------------------------------------------*
   Collision detection
  *----------------------------------------------------------------------*/

src/PaplRobwork.ml

   = "caml_robwork_getQ"
 external caml_robwork_gripFrame : frame_t -> frame_t -> state_t -> bool
   = "caml_robwork_gripFrame"
+external caml_robwork_getFrameName : frame_t -> string -> int -> int
+  = "caml_robwork_getFrameName"
 external caml_robwork_inCollision : workcell_t -> state_t -> bool
   = "caml_robwork_inCollision"
 external caml_robwork_makeTimedStatePath : unit -> time_state_path_t
 
 let copy_state state = caml_robwork_copyState state
 
+let get_frame_name frame =
+  let len = caml_robwork_getFrameName frame "" (-1) in
+  let name = String.make len ' ' in
+  let _ = caml_robwork_getFrameName frame name len in
+    name
+
 let grip_frame item frame state =
   if caml_robwork_gripFrame item frame state then ()
-  else die "PaplRobwork.grip_frame: item must be a movable DAF."
+  else
+    let msg =
+      "PaplRobwork.grip_frame: can't grip item '"
+        ^ get_frame_name item ^
+        "' with frame '"
+        ^ get_frame_name frame ^
+        "'. The item must be a movable DAF."
+    in die msg
 
 let in_collision workcell state =
   caml_robwork_inCollision workcell state
     CAMLreturn(Val_bool(robwork_gripFrame(item, gripper, state)));
 }
 
+value caml_robwork_getFrameName(
+    value frame_value, value result_value, value size_value)
+{
+    CAMLparam3(frame_value, result_value, size_value);
+
+    const RW_Frame* frame = Frame_val(frame_value);
+    char* result = String_val(result_value);
+    const int size = Int_val(size_value);
+
+    CAMLreturn(Val_int(robwork_getFrameName(frame, result, size)));
+}
+
 /*----------------------------------------------------------------------*
   Collision detection
  *----------------------------------------------------------------------*/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.