Fri Feb 25 10:33:57 AM HKT 2022

This commit is contained in:
Terence Tong 2022-02-25 10:33:57 +08:00
parent 06183fa710
commit 7e232e6021

View File

@ -1,16 +1,91 @@
# pspad
A new Flutter project.
Playstation like control pad to control turtlesim using roslibdart
## Getting Started
## How to use it
### Start rosbridge
```
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
```
### Start turtlesim in another terminal
```
ros2 run turtlesim turtlesim_node
```
### Start flutter control pad
```
cd pspad
flutter run -d linux
```
This project is a starting point for a Flutter application.
### How to use the control pad
```
void initState() {
ros = Ros(url: host);
cmdVelTopic = Topic(
ros: ros,
name: '/turtle1/cmd_vel',
type: "geometry_msgs/msg/Twist",
reconnectOnClose: true,
queueLength: 10,
queueSize: 10);
A few resources to get you started if this is your first Flutter project:
ros.connect();
super.initState();
Timer.periodic(const Duration(milliseconds: 200), directionFired);
}
void leftCallback(int event) {
leftButtonState = event;
}
void directionFired(Timer timer) {
var linear = {'x': 0.0, 'y': 0.0, 'z': 0.0};
var angular = {'x': 0.0, 'y': 0.0, 'z': 0.0};
if (leftButtonState == -1) {
linear = {'x': 0.0, 'y': 0.0, 'z': 0.0};
angular = {'x': 0.0, 'y': 0.0, 'z': turnAngularVelocity};
} else if (rightButtonState == -1) {
linear = {'x': 0.0, 'y': 0.0, 'z': 0.0};
angular = {'x': 0.0, 'y': 0.0, 'z': -turnAngularVelocity};
} else if (forwardButtonState == -1) {
linear = {'x': forwardVelocity, 'y': 0.0, 'z': 0.0};
angular = {'x': 0.0, 'y': 0.0, 'z': 0};
} else if (backwardButtonState == -1) {
linear = {'x': -forwardVelocity, 'y': 0.0, 'z': 0.0};
angular = {'x': 0.0, 'y': 0.0, 'z': 0};
}
var twist = {'linear': linear, 'angular': angular};
if (lastDirectionTwist == twist &&
twist['linear'] == {'x': 0.0, 'y': 0.0, 'z': 0.0} &&
twist['angular'] == {'x': 0.0, 'y': 0.0, 'z': 0.0}) {
return;
}
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
cmdVelTopic.publish(twist);
lastDirectionTwist = twist;
}
Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Container(
margin: const EdgeInsets.all(50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
DirectionPad(
diameter: 200,
leftCallback: leftCallback,
rightCallback: rightCallback,
forwardCallback: forwardCallback,
backwardCallback: backwardCallback,
),
KeyPad(
diameter: 200,
squareCallback: squareCallback,
circleCallback: circleCallback,
triangleCallback: triangleCallback,
crossCallback: crossCallback,
),
],
),
)
),
```