@@ -7,19 +7,33 @@ import PropTypes from 'prop-types'
7
7
import { View } from 'react-native'
8
8
9
9
// 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'
11
21
import '../Home/Home.css'
12
22
import {
23
+ CARTESIAN_CONTROLLER_NAME ,
24
+ JOINT_CONTROLLER_NAME ,
13
25
ROBOT_BASE_LINK ,
14
26
ROBOT_JOINTS ,
15
27
SERVO_CARTESIAN_TOPIC ,
16
28
SERVO_CARTESIAN_TOPIC_MSG ,
17
29
SERVO_JOINT_TOPIC ,
18
30
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
23
37
} from '../Constants'
24
38
import { useGlobalState } from '../GlobalState'
25
39
import HoldButton from '../../buttons/HoldButton'
@@ -122,11 +136,17 @@ const TeleopSubcomponent = (props) => {
122
136
/**
123
137
* Create the ROS Action Client to start the teleop controllers.
124
138
*/
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 )
130
150
} , [ ] )
131
151
132
152
/**
@@ -144,9 +164,9 @@ const TeleopSubcomponent = (props) => {
144
164
*/
145
165
useEffect ( ( ) => {
146
166
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 ] )
150
170
151
171
/**
152
172
* When the component is unmounted, stop servo.
@@ -155,11 +175,10 @@ const TeleopSubcomponent = (props) => {
155
175
let unmountCallback = props . unmountCallback
156
176
return ( ) => {
157
177
console . log ( 'Unmounting teleop subcomponent.' )
158
- destroyActionClient ( startCartesianControllerAction )
159
- destroyActionClient ( startJointControllerAction )
178
+ destroyActionClient ( activateControllerAction )
160
179
unmountCallback . current ( )
161
180
}
162
- } , [ startCartesianControllerAction , startJointControllerAction , props . unmountCallback ] )
181
+ } , [ activateControllerAction , props . unmountCallback ] )
163
182
164
183
/**
165
184
* Callback function to publish constant cartesian cartesian velocity commands.
@@ -534,6 +553,38 @@ const TeleopSubcomponent = (props) => {
534
553
} ,
535
554
[ teleopMode , setTeleopMode , textFontSize , sizeSuffix ]
536
555
)
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
+
537
588
// Render the component
538
589
return (
539
590
< View
@@ -562,7 +613,7 @@ const TeleopSubcomponent = (props) => {
562
613
</ View >
563
614
< View
564
615
style = { {
565
- flex : 9 ,
616
+ flex : 14 ,
566
617
justifyContent : 'center' ,
567
618
alignItems : 'center' ,
568
619
width : '100%' ,
@@ -572,7 +623,7 @@ const TeleopSubcomponent = (props) => {
572
623
{ /* Allow users to tune to speed of the current teleop mode */ }
573
624
< View
574
625
style = { {
575
- flex : 1 ,
626
+ flex : props . allowIncreasingForceThreshold ? 1 : 2 ,
576
627
flexDirection : 'row' ,
577
628
justifyContent : 'center' ,
578
629
alignItems : 'center' ,
@@ -628,10 +679,58 @@ const TeleopSubcomponent = (props) => {
628
679
} }
629
680
/>
630
681
</ 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
+ ) }
631
730
{ /* Render the controls for the mode */ }
632
731
< View
633
732
style = { {
634
- flex : 5 ,
733
+ flex : 8 ,
635
734
flexDirection : 'column' ,
636
735
justifyContent : 'center' ,
637
736
alignItems : 'center' ,
@@ -652,10 +751,13 @@ TeleopSubcomponent.propTypes = {
652
751
// A reference to a function to be called if StopServo is succesfully run.
653
752
unmountCallback : PropTypes . object ,
654
753
// 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
656
757
}
657
758
TeleopSubcomponent . defaultProps = {
658
759
unmountCallback : { current : ( ) => { } } ,
659
- teleopButtonOnReleaseCallback : ( ) => { }
760
+ teleopButtonOnReleaseCallback : ( ) => { } ,
761
+ allowIncreasingForceThreshold : false
660
762
}
661
763
export default TeleopSubcomponent
0 commit comments