Skip to content

Commit

Permalink
made send_ik_movement_* work
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-cavalcanti committed Oct 10, 2023
1 parent 9aef526 commit 70a0ed3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion c_transpiler/assets/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def getObjectSelection(self)->list[int]:
def setObjectSelection(self,objectHandles:list[float])->None:
...

def getStringSignal(self,signalName:str)->str:
def getStringSignal(self,signalName:str)->Optional[list[int]]:
...

def getInt32Signal(self,signalName:str)->Optional[int]:
Expand Down
2 changes: 1 addition & 1 deletion c_transpiler/assets/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait Sim : RemoteApiClientInterface {
(sim_set_vision_sensor_char_image,"setVisionSensorCharImage",(sensor_handle:i64,image:Vec<u8>)->()),
(sim_get_object_selection,"getObjectSelection"->Vec<i64>),
(sim_set_object_selection,"setObjectSelection",(object_handles:Vec<f64>)->()),
(sim_get_string_signal,"getStringSignal",(signal_name:String)->String),
(sim_get_string_signal,"getStringSignal",(signal_name:String)->Option<Vec<u8>>),
(sim_get_int32_signal,"getInt32Signal",(signal_name:String)->Option<i64>),
(sim_get_float_signal,"getFloatSignal",(signal_name:String)->Option<f64>),
(sim_acquire_lock,"acquireLock"->()),
Expand Down
2 changes: 1 addition & 1 deletion c_transpiler/assets/sim_api_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void setObjectSelection(std::vector<double> objectHandles);
// DEPRECATED/BACKCOMPATIBILITY START

// SPECIAL START
std::string getStringSignal(std::string signalName);
std::optional<std::vector<uint8_t>> getStringSignal(std::string signalName);
std::optional<int64_t> getInt32Signal(std::string signalName);
std::optional<double> getFloatSignal(std::string signalName);
// SPECIAL END
Expand Down
11 changes: 8 additions & 3 deletions examples/send_ik_movement_sequence_mov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ fn wait_for_movement_executed<S: Sim>(
sim: &S,
signal_name: String,
) -> Result<(), RemoteAPIError> {
let mut string = sim.sim_get_string_signal(signal_name.clone())?;
while string != id {
string = sim.sim_get_string_signal(signal_name.clone())?;
loop {
let bytes = sim.sim_get_string_signal(signal_name.clone())?;
if let Some(bytes) = bytes {
let utf8_string = String::from_utf8(bytes).unwrap();
if utf8_string == id {
break;
}
}
}

Ok(())
Expand Down
11 changes: 8 additions & 3 deletions examples/send_ik_movement_sequence_pts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,14 @@ fn wait_for_movement_executed<S: Sim>(
sim: &S,
signal_name: String,
) -> Result<(), RemoteAPIError> {
let mut string = sim.sim_get_string_signal(signal_name.clone())?;
while string != id {
string = sim.sim_get_string_signal(signal_name.clone())?;
loop {
let bytes = sim.sim_get_string_signal(signal_name.clone())?;
if let Some(bytes) = bytes {
let utf8_string = String::from_utf8(bytes).unwrap();
if utf8_string == id {
break;
}
}
}

Ok(())
Expand Down
61 changes: 24 additions & 37 deletions src/remote_api_objects/sim/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::Sim;
use super::*;
use crate::{
log_utils,
remote_api_objects::mocks::{assert_payload, MockRemoteAPIClient},
};
use crate::remote_api_objects::mocks::{assert_payload, MockRemoteAPIClient};
use serde_json::json;

use crate::remote_api_objects::connection_error::RemoteAPIError;
Expand Down Expand Up @@ -111,57 +108,47 @@ fn test_synchronous_image_transmission_functions() -> Result<(), RemoteAPIError>
fn test_send_ik_movement_sequence_mov_functions() -> Result<(), RemoteAPIError> {
env_logger::init();

let sim = MockRemoteAPIClient::new_sucess();
let mut sim = MockRemoteAPIClient::new_sucess();
sim.uuid = "782cad7d-4493-42f2-a715-69f740f26ea9".to_string();

let handle_id = sim.sim_get_object(String::from("/LBR4p"), None)?;
assert_eq!(handle_id, 1);

assert_payload!(sim, b"\xa2dfuncmsim.getObjectdargs\x81f/LBR4p");
assert_payload!(sim, b"\xa5dfuncmsim.getObjectdargs\x81f/LBR4pduuidx$782cad7d-4493-42f2-a715-69f740f26ea9cver\x02dlangdrust");

let script_handle = sim.sim_get_script(1, Some(13), None)?;
assert_eq!(script_handle, 1);
assert_payload!(sim, b"\xa2dfuncmsim.getScriptdargs\x82\x01\r");
assert_payload!(sim, b"\xa5dfuncmsim.getScriptdargs\x82\x01\rduuidx$782cad7d-4493-42f2-a715-69f740f26ea9cver\x02dlangdrust");

*sim.result.borrow_mut() = serde_json::json!(json!({"ret":{},"success":true}));
*sim.result.borrow_mut() = serde_json::json!(json!({"ret":[[114,101,97,100,121]]}));
let signal = sim.sim_get_string_signal(String::from("/LBR4p_executedMovId"))?;
assert_payload!(
sim,
b"\xa2dfuncssim.getStringSignaldargs\x81t/LBR4p_executedMovId"
b"\xa5dfuncssim.getStringSignaldargs\x81t/LBR4p_executedMovIdduuidx$782cad7d-4493-42f2-a715-69f740f26ea9cver\x02dlangdrust"
);
assert!(signal.is_empty());

*sim.result.borrow_mut() = json!({"ret":["ready"],"success":true});
let signal = sim.sim_get_string_signal(String::from("/LBR4p_executedMovId"))?;
assert_payload!(
sim,
b"\xa2dfuncssim.getStringSignaldargs\x81t/LBR4p_executedMovId"
);
assert_eq!(signal, "ready");

*sim.result.borrow_mut() = json!({"success": true,"ret": [[0.0051022060215473175, -7.424_468_640_238_047e-5, 1.072655200958252, 3.102_603_295_701_556e-5, 3.624_804_958_235_472_4e-5, -0.0001559544907649979, 1], [-0.0008084774017333984, -0.5228924751281738, -0.0008318424224853516, 1.0469286441802979, 0.0001537799835205078, -0.5236260890960693, -6.67572021484375e-06]]});
let json =
sim.sim_call_script_function(String::from("remoteApi_getPoseAndConfig"), 2050006, None)?;
assert_payload!(sim,b"\xa2dfuncvsim.callScriptFunctiondargs\x82x\x1aremoteApi_getPoseAndConfig\x1a\x00\x1fG\xd6");
assert_eq!(
json,
json! {[[0.0051022060215473175, -7.424_468_640_238_047e-5, 1.072655200958252, 3.102_603_295_701_556e-5, 3.624_804_958_235_472_4e-5, -0.0001559544907649979, 1], [-0.0008084774017333984, -0.5228924751281738, -0.0008318424224853516, 1.0469286441802979, 0.0001537799835205078, -0.5236260890960693, -6.67572021484375e-06]]}
);
let signal = String::from_utf8(signal.unwrap()).unwrap();
assert_eq!(signal, "ready".to_string());

let script_handle = 1010073;

*sim.result.borrow_mut() = json!({"ret":[[0.005610920649735013,-0.00021765310913694194,1.0726233629223674,0.00015426587889780238,0.00035320923886966716,0.0002262267625328107,0.999999900133357],[-0.00016239643955495708,-0.523748620585974,6.142930608632469e-10,1.047150871028287,0.00003561749575364814,-0.523602489795632,-3.7685468967652014e-8]]});
let _json = sim.sim_call_script_function(
String::from("remoteApi_getPoseAndConfig"),
script_handle,
None,
)?;

assert_payload!(sim,b"\xa5dfuncvsim.callScriptFunctiondargs\x82x\x1aremoteApi_getPoseAndConfig\x1a\x00\x0fi\x99duuidx$782cad7d-4493-42f2-a715-69f740f26ea9cver\x02dlangdrust");

*sim.result.borrow_mut() = json! {{"ret":[{}],"success":true}};
let json_arg = json!( {"id": "movSeq1", "type": "mov", "targetPose": [0, 0, 0.85, 0, 0, 0, 1], "maxVel": 0.1, "maxAccel": 0.01});
let json_out = sim.sim_call_script_function(
let _json_out = sim.sim_call_script_function(
String::from("remoteApi_movementDataFunction"),
2050006,
script_handle,
Some(json_arg),
)?;
let payload = sim.get_payload();
let decoded: ciborium::value::Value = ciborium::de::from_reader(payload.as_slice()).unwrap();

let json = serde_json::json!(decoded);
println!("Json response: {}", json);
println!("{}", log_utils::to_byte_array_string(&payload));

assert_payload!(sim,b"\xa2dfuncvsim.callScriptFunctiondargs\x83x\x1eremoteApi_movementDataFunction\x1a\x00\x1fG\xd6\xa5bidgmovSeq1hmaxAccel\xfb?\x84z\xe1G\xae\x14{fmaxVel\xfb?\xb9\x99\x99\x99\x99\x99\x9ajtargetPose\x87\x00\x00\xfb?\xeb333333\x00\x00\x00\x01dtypecmov");
assert_eq!(json_out, json!({}));
assert_payload!(sim,b"\xa5dfuncvsim.callScriptFunctiondargs\x83x\x1eremoteApi_movementDataFunction\x1a\x00\x0fi\x99\xa5bidgmovSeq1hmaxAccel\xfb?\x84z\xe1G\xae\x14{fmaxVel\xfb?\xb9\x99\x99\x99\x99\x99\x9ajtargetPose\x87\x00\x00\xfb?\xeb333333\x00\x00\x00\x01dtypecmovduuidx$782cad7d-4493-42f2-a715-69f740f26ea9cver\x02dlangdrust");

Ok(())
}
Expand Down

0 comments on commit 70a0ed3

Please sign in to comment.