Skip to content

Commit e7ca7eb

Browse files
authored
Allow retaring the FT sensor from the teleop subcomponent (#142)
1 parent 1d295fc commit e7ca7eb

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

feedingwebapp/src/Pages/Constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ ROS_SERVICE_NAMES[MEAL_STATE.U_BiteAcquisitionCheck] = {
118118
export { ROS_SERVICE_NAMES }
119119
export const CLEAR_OCTOMAP_SERVICE_NAME = 'clear_octomap'
120120
export const CLEAR_OCTOMAP_SERVICE_TYPE = 'std_srvs/srv/Empty'
121+
export const RETARE_FT_SENSOR_SERVICE_NAME = 'wireless_ft/set_bias'
122+
export const RETARE_FT_SENSOR_SERVICE_TYPE = 'std_srvs/srv/SetBool'
121123
export const ACQUISITION_REPORT_SERVICE_NAME = 'ada_feeding_action_select/action_report'
122124
export const ACQUISITION_REPORT_SERVICE_TYPE = 'ada_feeding_msgs/srv/AcquisitionReport'
123125
export const GET_ROBOT_STATE_SERVICE_NAME = 'get_robot_state'

feedingwebapp/src/Pages/Header/InfoModal.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function InfoModal(props) {
124124
{mode === VIDEO_MODE ? (
125125
<VideoFeed topic={CAMERA_FEED_TOPIC} updateRateHz={10} webrtcURL={props.webrtcURL} />
126126
) : mode === TELEOP_MODE ? (
127-
<TeleopSubcomponent allowIncreasingForceThreshold={true} />
127+
<TeleopSubcomponent allowIncreasingForceThreshold={true} allowRetaringFTSensor={true} />
128128
) : mode === SYSTEM_STATUS_MODE ? (
129129
<div>System Status</div>
130130
) : (

feedingwebapp/src/Pages/Header/TeleopSubcomponent.jsx

+54-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import {
3030
SERVO_JOINT_TOPIC_MSG,
3131
ACTIVATE_CONTROLLER_ACTION_NAME,
3232
ACTIVATE_CONTROLLER_ACTION_TYPE,
33-
SET_PARAMETERS_SERVICE_NAME,
33+
SET_PARAMETERS_SERVICE_TYPE,
34+
RETARE_FT_SENSOR_SERVICE_NAME,
35+
RETARE_FT_SENSOR_SERVICE_TYPE,
3436
INCREASED_FORCE_THRESHOLD,
3537
DEFAULT_FORCE_THRESHOLD,
3638
FORCE_THRESHOLD_PARAM
@@ -561,7 +563,7 @@ const TeleopSubcomponent = (props) => {
561563
const [forceThresholdIsIncreased, setForceThresholdIsIncreased] = useState(false)
562564
let changeForceThresholdService = useMemo(() => {
563565
let activeController = teleopMode === JOINT_MODE ? JOINT_CONTROLLER_NAME : CARTESIAN_CONTROLLER_NAME
564-
return createROSService(ros.current, activeController + '/set_parameters_atomically', SET_PARAMETERS_SERVICE_NAME)
566+
return createROSService(ros.current, activeController + '/set_parameters_atomically', SET_PARAMETERS_SERVICE_TYPE)
565567
}, [ros, teleopMode])
566568
const setForceThreshold = useCallback(
567569
(threshold) => {
@@ -585,6 +587,21 @@ const TeleopSubcomponent = (props) => {
585587
}
586588
}, [props.allowIncreasingForceThreshold, setForceThreshold])
587589

590+
/**
591+
* Service and callback for retaring the force-torque sensor.
592+
*/
593+
let reTareService = useMemo(() => {
594+
return createROSService(ros.current, RETARE_FT_SENSOR_SERVICE_NAME, RETARE_FT_SENSOR_SERVICE_TYPE)
595+
}, [ros])
596+
const reTareFTSensor = useCallback(() => {
597+
let service = reTareService
598+
let request = createROSServiceRequest({ data: true })
599+
console.log('Calling reTareFTSensor with request', request)
600+
service.callService(request, (response) => {
601+
console.log('For reTareFTSensor request', request, 'received response', response)
602+
})
603+
}, [reTareService])
604+
588605
// Render the component
589606
return (
590607
<View
@@ -727,6 +744,36 @@ const TeleopSubcomponent = (props) => {
727744
) : (
728745
<></>
729746
)}
747+
{/* If the props specify, show a button to re-tare the force-torque sensor */}
748+
{props.allowRetaringFTSensor ? (
749+
<View
750+
style={{
751+
flex: 1,
752+
flexDirection: 'row',
753+
justifyContent: 'center',
754+
alignItems: 'center',
755+
width: '100%'
756+
}}
757+
>
758+
<Button
759+
variant='warning'
760+
className='mx-2 mb-2 btn-huge'
761+
size='lg'
762+
style={{
763+
fontSize: (textFontSize * 1.0).toString() + sizeSuffix,
764+
paddingTop: 0,
765+
paddingBottom: 0,
766+
margin: '0 !important',
767+
width: '100%'
768+
}}
769+
onClick={reTareFTSensor}
770+
>
771+
&#x2696; Re-Zero Force Sensor
772+
</Button>
773+
</View>
774+
) : (
775+
<></>
776+
)}
730777
{/* Render the controls for the mode */}
731778
<View
732779
style={{
@@ -753,11 +800,14 @@ TeleopSubcomponent.propTypes = {
753800
// A function to be called when one of the teleop buttons are released
754801
teleopButtonOnReleaseCallback: PropTypes.func,
755802
// Whether to allow the user to increase the force threshold
756-
allowIncreasingForceThreshold: PropTypes.bool
803+
allowIncreasingForceThreshold: PropTypes.bool,
804+
// Whether to allow the user to retare the force-torque sensor
805+
allowRetaringFTSensor: PropTypes.bool
757806
}
758807
TeleopSubcomponent.defaultProps = {
759808
unmountCallback: { current: () => {} },
760809
teleopButtonOnReleaseCallback: () => {},
761-
allowIncreasingForceThreshold: false
810+
allowIncreasingForceThreshold: false,
811+
allowRetaringFTSensor: false
762812
}
763813
export default TeleopSubcomponent

0 commit comments

Comments
 (0)