@@ -7,19 +7,33 @@ import PropTypes from 'prop-types'
77import { View } from 'react-native'
88
99// Local Imports
10- import { useROS , createROSTopic , createROSMessage , createROSActionClient , callROSAction , destroyActionClient } from '../../ros/ros_helpers'
10+ import {
11+ useROS ,
12+ createROSTopic ,
13+ createROSMessage ,
14+ createROSActionClient ,
15+ callROSAction ,
16+ destroyActionClient ,
17+ createROSService ,
18+ createROSServiceRequest ,
19+ getParameterFromValue
20+ } from '../../ros/ros_helpers'
1121import '../Home/Home.css'
1222import {
23+ CARTESIAN_CONTROLLER_NAME ,
24+ JOINT_CONTROLLER_NAME ,
1325 ROBOT_BASE_LINK ,
1426 ROBOT_JOINTS ,
1527 SERVO_CARTESIAN_TOPIC ,
1628 SERVO_CARTESIAN_TOPIC_MSG ,
1729 SERVO_JOINT_TOPIC ,
1830 SERVO_JOINT_TOPIC_MSG ,
19- START_CARTESIAN_CONTROLLER_ACTION_NAME ,
20- START_CARTESIAN_CONTROLLER_ACTION_TYPE ,
21- START_JOINT_CONTROLLER_ACTION_NAME ,
22- START_JOINT_CONTROLLER_ACTION_TYPE
31+ ACTIVATE_CONTROLLER_ACTION_NAME ,
32+ ACTIVATE_CONTROLLER_ACTION_TYPE ,
33+ SET_PARAMETERS_SERVICE_NAME ,
34+ INCREASED_FORCE_THRESHOLD ,
35+ DEFAULT_FORCE_THRESHOLD ,
36+ FORCE_THRESHOLD_PARAM
2337} from '../Constants'
2438import { useGlobalState } from '../GlobalState'
2539import HoldButton from '../../buttons/HoldButton'
@@ -122,11 +136,17 @@ const TeleopSubcomponent = (props) => {
122136 /**
123137 * Create the ROS Action Client to start the teleop controllers.
124138 */
125- let startCartesianControllerAction = useMemo ( ( ) => {
126- return createROSActionClient ( ros . current , START_CARTESIAN_CONTROLLER_ACTION_NAME , START_CARTESIAN_CONTROLLER_ACTION_TYPE )
127- } , [ ] )
128- let startJointControllerAction = useMemo ( ( ) => {
129- return createROSActionClient ( ros . current , START_JOINT_CONTROLLER_ACTION_NAME , START_JOINT_CONTROLLER_ACTION_TYPE )
139+ let activateControllerActionGoal = useMemo (
140+ ( ) =>
141+ createROSMessage ( {
142+ controller_to_activate : teleopMode === JOINT_MODE ? JOINT_CONTROLLER_NAME : CARTESIAN_CONTROLLER_NAME ,
143+ re_tare : true
144+ } ) ,
145+ [ teleopMode ]
146+ )
147+
148+ let activateControllerAction = useMemo ( ( ) => {
149+ return createROSActionClient ( ros . current , ACTIVATE_CONTROLLER_ACTION_NAME , ACTIVATE_CONTROLLER_ACTION_TYPE )
130150 } , [ ] )
131151
132152 /**
@@ -144,9 +164,9 @@ const TeleopSubcomponent = (props) => {
144164 */
145165 useEffect ( ( ) => {
146166 console . log ( 'Starting controller' , refreshCount )
147- let action = teleopMode === JOINT_MODE ? startJointControllerAction : startCartesianControllerAction
148- callROSAction ( action , createROSMessage ( { } ) , null , null )
149- } , [ refreshCount , startCartesianControllerAction , startJointControllerAction , teleopMode ] )
167+ let action = activateControllerAction
168+ callROSAction ( action , activateControllerActionGoal , null , null )
169+ } , [ refreshCount , activateControllerAction , activateControllerActionGoal ] )
150170
151171 /**
152172 * When the component is unmounted, stop servo.
@@ -155,11 +175,10 @@ const TeleopSubcomponent = (props) => {
155175 let unmountCallback = props . unmountCallback
156176 return ( ) => {
157177 console . log ( 'Unmounting teleop subcomponent.' )
158- destroyActionClient ( startCartesianControllerAction )
159- destroyActionClient ( startJointControllerAction )
178+ destroyActionClient ( activateControllerAction )
160179 unmountCallback . current ( )
161180 }
162- } , [ startCartesianControllerAction , startJointControllerAction , props . unmountCallback ] )
181+ } , [ activateControllerAction , props . unmountCallback ] )
163182
164183 /**
165184 * Callback function to publish constant cartesian cartesian velocity commands.
@@ -534,6 +553,38 @@ const TeleopSubcomponent = (props) => {
534553 } ,
535554 [ teleopMode , setTeleopMode , textFontSize , sizeSuffix ]
536555 )
556+
557+ /**
558+ * Service and callback to increase the force threshold. Additionally, before
559+ * unmounting, the force threshold should be reset.
560+ */
561+ const [ forceThresholdIsIncreased , setForceThresholdIsIncreased ] = useState ( false )
562+ let changeForceThresholdService = useMemo ( ( ) => {
563+ let activeController = teleopMode === JOINT_MODE ? JOINT_CONTROLLER_NAME : CARTESIAN_CONTROLLER_NAME
564+ return createROSService ( ros . current , activeController + '/set_parameters_atomically' , SET_PARAMETERS_SERVICE_NAME )
565+ } , [ ros , teleopMode ] )
566+ const setForceThreshold = useCallback (
567+ ( threshold ) => {
568+ let service = changeForceThresholdService
569+ let request = createROSServiceRequest ( {
570+ parameters : [ { name : FORCE_THRESHOLD_PARAM , value : getParameterFromValue ( threshold , 3 ) } ]
571+ } )
572+ console . log ( 'Calling setForceThreshold with request' , request , 'for service' , service . name )
573+ service . callService ( request , ( response ) => {
574+ console . log ( 'For setForceThreshold request' , request , 'received response' , response )
575+ setForceThresholdIsIncreased ( threshold > DEFAULT_FORCE_THRESHOLD )
576+ } )
577+ } ,
578+ [ changeForceThresholdService , setForceThresholdIsIncreased ]
579+ )
580+ useEffect ( ( ) => {
581+ return ( ) => {
582+ if ( props . allowIncreasingForceThreshold ) {
583+ setForceThreshold ( DEFAULT_FORCE_THRESHOLD )
584+ }
585+ }
586+ } , [ props . allowIncreasingForceThreshold , setForceThreshold ] )
587+
537588 // Render the component
538589 return (
539590 < View
@@ -562,7 +613,7 @@ const TeleopSubcomponent = (props) => {
562613 </ View >
563614 < View
564615 style = { {
565- flex : 9 ,
616+ flex : 14 ,
566617 justifyContent : 'center' ,
567618 alignItems : 'center' ,
568619 width : '100%' ,
@@ -572,7 +623,7 @@ const TeleopSubcomponent = (props) => {
572623 { /* Allow users to tune to speed of the current teleop mode */ }
573624 < View
574625 style = { {
575- flex : 1 ,
626+ flex : props . allowIncreasingForceThreshold ? 1 : 2 ,
576627 flexDirection : 'row' ,
577628 justifyContent : 'center' ,
578629 alignItems : 'center' ,
@@ -628,10 +679,58 @@ const TeleopSubcomponent = (props) => {
628679 } }
629680 />
630681 </ View >
682+ { /* If the props specify, show a button to increase the force threshold. */ }
683+ { props . allowIncreasingForceThreshold ? (
684+ < View
685+ style = { {
686+ flex : 1 ,
687+ flexDirection : 'row' ,
688+ justifyContent : 'center' ,
689+ alignItems : 'center' ,
690+ width : '100%'
691+ } }
692+ >
693+ { forceThresholdIsIncreased ? (
694+ < Button
695+ variant = 'warning'
696+ className = 'mx-2 mb-2 btn-huge'
697+ size = 'lg'
698+ style = { {
699+ fontSize : ( textFontSize * 1.0 ) . toString ( ) + sizeSuffix ,
700+ paddingTop : 0 ,
701+ paddingBottom : 0 ,
702+ margin : '0 !important' ,
703+ width : '100%'
704+ } }
705+ onClick = { ( ) => setForceThreshold ( DEFAULT_FORCE_THRESHOLD ) }
706+ >
707+ ⛨ Restore Force Threshold
708+ </ Button >
709+ ) : (
710+ < Button
711+ variant = 'danger'
712+ className = 'mx-2 mb-2 btn-huge'
713+ size = 'lg'
714+ style = { {
715+ fontSize : ( textFontSize * 1.0 ) . toString ( ) + sizeSuffix ,
716+ paddingTop : 0 ,
717+ paddingBottom : 0 ,
718+ margin : '0 !important' ,
719+ width : '100%'
720+ } }
721+ onClick = { ( ) => setForceThreshold ( INCREASED_FORCE_THRESHOLD ) }
722+ >
723+ ⚠ Increase Force Threshold
724+ </ Button >
725+ ) }
726+ </ View >
727+ ) : (
728+ < > </ >
729+ ) }
631730 { /* Render the controls for the mode */ }
632731 < View
633732 style = { {
634- flex : 5 ,
733+ flex : 8 ,
635734 flexDirection : 'column' ,
636735 justifyContent : 'center' ,
637736 alignItems : 'center' ,
@@ -652,10 +751,13 @@ TeleopSubcomponent.propTypes = {
652751 // A reference to a function to be called if StopServo is succesfully run.
653752 unmountCallback : PropTypes . object ,
654753 // A function to be called when one of the teleop buttons are released
655- teleopButtonOnReleaseCallback : PropTypes . func
754+ teleopButtonOnReleaseCallback : PropTypes . func ,
755+ // Whether to allow the user to increase the force threshold
756+ allowIncreasingForceThreshold : PropTypes . bool
656757}
657758TeleopSubcomponent . defaultProps = {
658759 unmountCallback : { current : ( ) => { } } ,
659- teleopButtonOnReleaseCallback : ( ) => { }
760+ teleopButtonOnReleaseCallback : ( ) => { } ,
761+ allowIncreasingForceThreshold : false
660762}
661763export default TeleopSubcomponent
0 commit comments