Skip to content

Commit

Permalink
added some deprecaded functions for pController example works
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-cavalcanti committed Oct 10, 2023
1 parent ba6711d commit 2e97631
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
27 changes: 27 additions & 0 deletions c_transpiler/assets/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@

class Sim(Protocol):

def setJointMaxForce(self,objectHandle:int, forceOrTorque:float)->None:
...

def getJointMaxForce(self,jointHandle:int)->float:
...

def createPureShape(self,primitiveType:int, options:int, sizes:list[float], mass:float, precision:Optional[list[int]] = None)->int:
...

def removeObject(self,objectHandle:int)->None:
...

def getVisionSensorDepthBuffer(self,sensorHandle:int, pos:Optional[list[int]] = None, size:Optional[list[int]] = None)->tuple[list[int], list[int]]:
...

def getVisionSensorCharImage(self,sensorHandle:int, pos:Optional[list[int]] = None, size:Optional[list[int]] = None)->tuple[list[int], list[int]]:
...

def setVisionSensorCharImage(self,sensorHandle:int, image:list[int])->None:
...

def getObjectSelection(self)->list[int]:
...

def setObjectSelection(self,objectHandles:list[float])->None:
...

def getStringSignal(self,signalName:str)->str:
...

Expand Down
9 changes: 9 additions & 0 deletions c_transpiler/assets/sim.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
pub trait Sim : RemoteApiClientInterface {
requests!{
"sim",
(sim_set_joint_max_force,"setJointMaxForce",(object_handle:i64,force_or_torque:f64)->()),
(sim_get_joint_max_force,"getJointMaxForce",(joint_handle:i64)->f64),
(sim_create_pure_shape,"createPureShape",(primitive_type:i64,options:i64,sizes:Vec<f64>,mass:f64),opt(precision:Vec<i64>)->i64),
(sim_remove_object,"removeObject",(object_handle:i64)->()),
(sim_get_vision_sensor_depth_buffer,"getVisionSensorDepthBuffer",(sensor_handle:i64),opt(pos:Vec<i64>,size:Vec<i64>)->(Vec<u8>,Vec<i64>)),
(sim_get_vision_sensor_char_image,"getVisionSensorCharImage",(sensor_handle:i64),opt(pos:Vec<i64>,size:Vec<i64>)->(Vec<u8>,Vec<i64>)),
(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_int32_signal,"getInt32Signal",(signal_name:String)->Option<i64>),
(sim_get_float_signal,"getFloatSignal",(signal_name:String)->Option<f64>),
Expand Down
21 changes: 21 additions & 0 deletions c_transpiler/assets/sim_api_header.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
// DEPRECATED/BACKCOMPATIBILITY START
void setJointMaxForce(int64_t objectHandle, double forceOrTorque);
double getJointMaxForce(int64_t jointHandle);
int64_t createPureShape(int64_t primitiveType, int64_t options,
std::vector<double> sizes, double mass,
std::optional<std::vector<int64_t>> precision = {});
void removeObject(int64_t objectHandle);
std::tuple<std::vector<uint8_t>, std::vector<int64_t>>
getVisionSensorDepthBuffer(int64_t sensorHandle,
std::optional<std::vector<int64_t>> pos = {},
std::optional<std::vector<int64_t>> size = {});
std::tuple<std::vector<uint8_t>, std::vector<int64_t>>
getVisionSensorCharImage(int64_t sensorHandle,
std::optional<std::vector<int64_t>> pos = {},
std::optional<std::vector<int64_t>> size = {});
void setVisionSensorCharImage(int64_t sensorHandle, std::vector<uint8_t> image);

std::vector<int64_t> getObjectSelection();
void setObjectSelection(std::vector<double> objectHandles);
// DEPRECATED/BACKCOMPATIBILITY START

// SPECIAL START
std::string getStringSignal(std::string signalName);
std::optional<int64_t> getInt32Signal(std::string signalName);
Expand Down
2 changes: 1 addition & 1 deletion examples/p_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn move_to_angle<S: Sim>(
while (target_angle - *join_angle).abs() > 0.1 * PI / 180.0 {
let velocity = compute_target_velocity(target_angle, *join_angle);
sim.sim_set_joint_target_velocity(*joint_handle, velocity, None)?;
sim.sim_set_joint_target_force(*joint_handle, MAX_FORCE, None)?;
sim.sim_set_joint_max_force(*joint_handle, MAX_FORCE)?;
client.sim_step()?;
*join_angle = sim.sim_get_joint_position(*joint_handle)?;
}
Expand Down
14 changes: 8 additions & 6 deletions src/remote_api_objects/sim/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,28 @@ fn test_simple_test_functions() -> Result<(), RemoteAPIError> {

#[test]
fn test_p_controller_functions() -> Result<(), RemoteAPIError> {
let sim = MockRemoteAPIClient::new_sucess();
let mut sim = MockRemoteAPIClient::new_sucess();
sim.uuid = "92e1fde9-2d2c-4258-aafc-06d89efb8a7a".to_string();

let id = sim.sim_get_object("/Cuboid[0]/joint".to_string(), None)?;
assert_eq!(id, 1);
assert_payload!(sim, b"\xa2dfuncmsim.getObjectdargs\x81p/Cuboid[0]/joint");
assert_payload!(sim,b"\xa5dfuncmsim.getObjectdargs\x81p/Cuboid[0]/jointduuidx$92e1fde9-2d2c-4258-aafc-06d89efb8a7acver\x02dlangdrust");

*sim.result.borrow_mut() = json!({"ret":[1.2],"success":true});
let pos = sim.sim_get_joint_position(9)?;
assert_eq!(pos, 1.2);
assert_payload!(sim, b"\xa2dfunctsim.getJointPositiondargs\x81\t");
assert_payload!(sim, b"\xa5dfunctsim.getJointPositiondargs\x81\tduuidx$92e1fde9-2d2c-4258-aafc-06d89efb8a7acver\x02dlangdrust"
);

*sim.result.borrow_mut() = json!({"ret":[1],"success":true});
sim.sim_set_joint_target_velocity(9, std::f64::consts::TAU, None)?;
assert_payload!(
sim,
b"\xa2dfuncx\x1asim.setJointTargetVelocitydargs\x82\t\xfb@\x19!\xfbTD-\x18"
b"\xa5dfuncx\x1asim.setJointTargetVelocitydargs\x82\t\xfb@\x19!\xfbTD-\x18duuidx$92e1fde9-2d2c-4258-aafc-06d89efb8a7acver\x02dlangdrust"
);

sim.sim_set_joint_target_force(9, 100.0, None)?;
assert_payload!(sim, b"\xa2dfunctsim.setJointMaxForcedargs\x82\t\xf9V@");
sim.sim_set_joint_max_force(9, 100.0)?;
assert_payload!(sim, b"\xa5dfunctsim.setJointMaxForcedargs\x82\t\xf9V@duuidx$92e1fde9-2d2c-4258-aafc-06d89efb8a7acver\x02dlangdrust");

Ok(())
}
Expand Down

0 comments on commit 2e97631

Please sign in to comment.