Skip to content

Commit f64f5a3

Browse files
Jashan32marcnause
authored andcommitted
added depth limit to accelerometer
1 parent e0bf06f commit f64f5a3

6 files changed

Lines changed: 66 additions & 17 deletions

File tree

lib/l10n/app_en.arb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
"updatePeriod": "Update Period",
383383
"luxmeterUpdatePeriodHint": "Please provide time interval at which data will be updated (100 ms to 1000 ms)",
384384
"highLimit": "High Limit",
385+
"lowLimit": "Low Limit",
385386
"luxmeterHighLimitHint": "Please provide the maximum limit of lux value to be recorded (10 Lx to 10000 Lx)",
386387
"sensorGain": "Sensor Gain",
387388
"sensorGainHint": "Please set gain of the sensor",
@@ -391,7 +392,8 @@
391392
"ms": "ms",
392393
"inBuiltSensor": "In-built Sensor",
393394
"updatePeriodErrorMessage": "Entered update period is not within the limits!",
394-
"highLimitErrorMessage": "Entered High limit is not within the limits!",
395+
"highLimitErrorMessage": "High limit must be between 10 and 200 m/s².",
396+
"lowLimitErrorMessage": "Negative acceleration limit magnitude must be between 10 and 200 m/s².",
395397
"baroMeterBulletPoint1": "The Barometer can be used to measure Atmospheric pressure. This instrument is compatible with either the built in pressure sensor on any android device or the BMP-180 pressure sensor",
396398
"baroMeterBulletPoint2": "If you want to use the sensor BMP-180, connect the sensor to PSLab device as shown in the figure.",
397399
"baroMeterBulletPoint3": "The above pin configuration has to be same except for the pin GND. GND is meant for Ground and any of the PSLab device GND pins can be used since they are common.",
@@ -460,6 +462,7 @@
460462
"accelerometerConfigurations": "Accelerometer Configurations",
461463
"accelerometerUpdatePeriodHint": "Please provide time interval at which data will be updated",
462464
"accelerometerHighLimitHint": "Please provide the maximum limit of acceleration value to be recorded",
465+
"accelerometerLowLimitHint": "Please provide the magnitude of the negative acceleration limit to be recorded",
463466
"roboticArmIntro": "• A robotic arm is a programmable mechanical device that mimics the movement of a human arm.\n• It uses servo motors to control its motion, and these motors are operated using PWM signals.\n• The PSLab provides four PWM square wave generators (SQ1, SQ2, SQ3, SQ4), allowing control of up to four servo motors and enabling a robotic arm with up to four degrees of freedom.",
464467
"roboticArmConnection": "• In the above figure, SQ1 is connected to the signal pin of the first servo motor. The servo's GND pin is connected to both the PSLab’s GND and the external power supply GND, while the VCC pin is connected to the external power supply VCC.\n• Similarly, connect the remaining servos to SQ2, SQ3, and SQ4 along with their respective GND and power supply connections.\n• Once connected, each servo can be controlled using either circular sliders for manual control or a timeline-based sequence for automated movement.",
465468
"autoscan": "Autoscan",

lib/l10n/app_hi.arb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
"updatePeriod": "अपडेट टाइम",
381381
"luxmeterUpdatePeriodHint": "वो टाइम इंटरवल बताएं जिस पर डेटा अपडेट होगा (100 ms से 1000 ms)",
382382
"highLimit": "हाई लिमिट",
383+
"lowLimit": "लो लिमिट",
383384
"luxmeterHighLimitHint": "रिकॉर्ड करने के लिए लक्स की मैक्स लिमिट बताएं (10 Lx से 10000 Lx)",
384385
"sensorGain": "सेंसर गेन",
385386
"sensorGainHint": "सेंसर का गेन सेट करें",
@@ -389,7 +390,8 @@
389390
"ms": "ms",
390391
"inBuiltSensor": "बिल्ट-इन सेंसर",
391392
"updatePeriodErrorMessage": "लिखा गया अपडेट टाइम लिमिट से बाहर है!",
392-
"highLimitErrorMessage": "लिखी गई हाई लिमिट लिमिट से बाहर है!",
393+
"highLimitErrorMessage": "हाई लिमिट 10 से 200 m/s² के बीच होनी चाहिए।",
394+
"lowLimitErrorMessage": "नेगेटिव एक्सेलेरेशन लिमिट का मान 10 से 200 m/s² के बीच होना चाहिए।",
393395
"baroMeterBulletPoint1": "बैरोमीटर से हवा का प्रेशर मापते हैं। यह किसी भी Android डिवाइस के बिल्ट-इन प्रेशर सेंसर या BMP-180 प्रेशर सेंसर के साथ चलता है",
394396
"baroMeterBulletPoint2": "अगर BMP-180 सेंसर यूज़ करना है तो फोटो की तरह सेंसर को PSLab डिवाइस से जोड़ें।",
395397
"baroMeterBulletPoint3": "ऊपर वाला पिन कनेक्शन GND पिन को छोड़कर बाकी सब वैसा ही होगा। GND ग्राउंड के लिए है और PSLab का कोई भी GND पिन यूज़ कर सकते हैं क्योंकि वो कॉमन हैं।",
@@ -452,6 +454,7 @@
452454
"accelerometerConfigurations": "एक्सेलेरोमीटर सेटिंग्स",
453455
"accelerometerUpdatePeriodHint": "वो टाइम इंटरवल बताएं जिस पर डेटा अपडेट होगा",
454456
"accelerometerHighLimitHint": "रिकॉर्ड करने के लिए एक्सेलेरेशन की मैक्स लिमिट बताएं",
457+
"accelerometerLowLimitHint": "रिकॉर्ड करने के लिए नेगेटिव एक्सेलेरेशन लिमिट का मान बताएं",
455458
"roboticArmIntro": "• रोबोटिक आर्म एक प्रोग्राम होने वाली मशीन है जो इंसान की भुजा की तरह हिलती है।\n• इसकी मूवमेंट के लिए सर्वो मोटर लगती हैं, जो PWM सिग्नल से चलती हैं।\n• PSLab में चार PWM स्क्वेयर वेव जनरेटर (SQ1, SQ2, SQ3, SQ4) हैं — इनसे चार सर्वो मोटर तक कंट्रोल कर सकते हैं और चार डिग्री ऑफ फ्रीडम वाला रोबोटिक आर्म बना सकते हैं।",
456459
"roboticArmConnection": "• ऊपर वाली फोटो में SQ1 पहली सर्वो मोटर के सिग्नल पिन से जुड़ा है। सर्वो का GND पिन PSLab के GND और बाहरी पावर सप्लाई के GND दोनों से जुड़ा है, और VCC पिन बाहरी पावर सप्लाई के VCC से जुड़ा है।\n• इसी तरह बाकी सर्वो को SQ2, SQ3 और SQ4 से जोड़ें, साथ में उनके GND और पावर सप्लाई कनेक्शन भी।\n• कनेक्ट होने के बाद हर सर्वो को सर्कुलर स्लाइडर से मैनुअल चला सकते हैं या टाइमलाइन से ऑटोमैटिक चला सकते हैं।",
457460
"autoscan" : "ऑटोस्कैन",

lib/models/accelerometer_config.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
class AccelerometerConfig {
22
final int updatePeriod;
33
final int highLimit;
4+
final int lowLimit;
45
final String activeSensor;
56
final int sensorGain;
67
final bool includeLocationData;
78

89
const AccelerometerConfig({
910
this.updatePeriod = 1000,
10-
this.highLimit = 20,
11+
this.highLimit = 200,
12+
this.lowLimit = 200,
1113
this.activeSensor = 'In-built Sensor',
1214
this.sensorGain = 1,
1315
this.includeLocationData = true,
@@ -16,13 +18,15 @@ class AccelerometerConfig {
1618
AccelerometerConfig copyWith({
1719
int? updatePeriod,
1820
int? highLimit,
21+
int? lowLimit,
1922
String? activeSensor,
2023
int? sensorGain,
2124
bool? includeLocationData,
2225
}) {
2326
return AccelerometerConfig(
2427
updatePeriod: updatePeriod ?? this.updatePeriod,
2528
highLimit: highLimit ?? this.highLimit,
29+
lowLimit: lowLimit ?? this.lowLimit,
2630
activeSensor: activeSensor ?? this.activeSensor,
2731
sensorGain: sensorGain ?? this.sensorGain,
2832
includeLocationData: includeLocationData ?? this.includeLocationData,
@@ -33,6 +37,7 @@ class AccelerometerConfig {
3337
return {
3438
'updatePeriod': updatePeriod,
3539
'highLimit': highLimit,
40+
'lowLimit': lowLimit,
3641
'activeSensor': activeSensor,
3742
'sensorGain': sensorGain,
3843
'includeLocationData': includeLocationData,
@@ -42,7 +47,8 @@ class AccelerometerConfig {
4247
factory AccelerometerConfig.fromJson(Map<String, dynamic> json) {
4348
return AccelerometerConfig(
4449
updatePeriod: json['updatePeriod'] ?? 1000,
45-
highLimit: json['highLimit'] ?? 2000,
50+
highLimit: json['highLimit'] ?? 200,
51+
lowLimit: json['lowLimit'] ?? json['depthLimit'] ?? 200,
4652
activeSensor: json['activeSensor'] ?? 'In-built Sensor',
4753
sensorGain: json['sensorGain'] ?? 1,
4854
includeLocationData: json['includeLocationData'] ?? true,

lib/providers/accelerometer_config_provider.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class AccelerometerConfigProvider extends ChangeNotifier {
4646
_saveConfigToPrefs();
4747
}
4848

49+
void updateLowLimit(int lowLimit) {
50+
_config = _config.copyWith(lowLimit: lowLimit);
51+
notifyListeners();
52+
_saveConfigToPrefs();
53+
}
54+
4955
void updateActiveSensor(String activeSensor) {
5056
_config = _config.copyWith(activeSensor: activeSensor);
5157
notifyListeners();

lib/providers/accelerometer_state_provider.dart

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class AccelerometerStateProvider extends ChangeNotifier {
3939
StreamSubscription? _locationStream;
4040
Position? currentPosition;
4141
Function? onPlaybackEnd;
42-
double? get _currentLimit => _configProvider?.config.highLimit.toDouble();
42+
double? get _currentHighLimit => _configProvider?.config.highLimit.toDouble();
43+
double? get _currentLowLimit => _configProvider?.config.lowLimit.toDouble();
4344
void setConfigProvider(AccelerometerConfigProvider configProvider) {
4445
_configProvider = configProvider;
4546
}
@@ -211,21 +212,24 @@ class AccelerometerStateProvider extends ChangeNotifier {
211212
}
212213

213214
void _updateData() {
214-
final limit = _currentLimit;
215+
final highLimit = _currentHighLimit;
216+
final lowLimit = _currentLowLimit;
215217

216-
final bool shouldClip = limit != null && !_isPlayingBack;
218+
final bool shouldClip = !_isPlayingBack;
217219

218-
final x = (shouldClip && _accelerometerEvent.x > limit)
219-
? limit
220-
: _accelerometerEvent.x;
220+
final double x;
221+
final double y;
222+
final double z;
221223

222-
final y = (shouldClip && _accelerometerEvent.y > limit)
223-
? limit
224-
: _accelerometerEvent.y;
225-
226-
final z = (shouldClip && _accelerometerEvent.z > limit)
227-
? limit
228-
: _accelerometerEvent.z;
224+
if (shouldClip && highLimit != null && lowLimit != null) {
225+
x = _accelerometerEvent.x.clamp(-lowLimit, highLimit).toDouble();
226+
y = _accelerometerEvent.y.clamp(-lowLimit, highLimit).toDouble();
227+
z = _accelerometerEvent.z.clamp(-lowLimit, highLimit).toDouble();
228+
} else {
229+
x = _accelerometerEvent.x;
230+
y = _accelerometerEvent.y;
231+
z = _accelerometerEvent.z;
232+
}
229233

230234
_accelerometerEvent = AccelerometerEvent(x, y, z, DateTime.now());
231235

lib/view/accelerometer_config_screen.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AccelerometerConfigScreen extends StatefulWidget {
1919
class _AccelerometerConfigScreenState extends State<AccelerometerConfigScreen> {
2020
final TextEditingController _updatePeriodController = TextEditingController();
2121
final TextEditingController _highLimitController = TextEditingController();
22+
final TextEditingController _lowLimitController = TextEditingController();
2223
final TextEditingController _sensorGainController = TextEditingController();
2324
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
2425

@@ -30,6 +31,7 @@ class _AccelerometerConfigScreenState extends State<AccelerometerConfigScreen> {
3031
Provider.of<AccelerometerConfigProvider>(context, listen: false);
3132
_updatePeriodController.text = provider.config.updatePeriod.toString();
3233
_highLimitController.text = provider.config.highLimit.toString();
34+
_lowLimitController.text = provider.config.lowLimit.toString();
3335
_sensorGainController.text = provider.config.sensorGain.toString();
3436
});
3537
}
@@ -38,6 +40,7 @@ class _AccelerometerConfigScreenState extends State<AccelerometerConfigScreen> {
3840
void dispose() {
3941
_updatePeriodController.dispose();
4042
_highLimitController.dispose();
43+
_lowLimitController.dispose();
4144
_sensorGainController.dispose();
4245
super.dispose();
4346
}
@@ -140,6 +143,30 @@ class _AccelerometerConfigScreenState extends State<AccelerometerConfigScreen> {
140143
},
141144
hint: appLocalizations.accelerometerHighLimitHint,
142145
),
146+
ConfigInputItem(
147+
title: appLocalizations.lowLimit,
148+
value:
149+
'${provider.config.lowLimit} ${appLocalizations.meterPerSecondSquared}',
150+
controller: _lowLimitController,
151+
onChanged: (value) {
152+
final intValue = int.tryParse(value);
153+
if (intValue != null &&
154+
intValue >= 10 &&
155+
intValue <= 200) {
156+
provider.updateLowLimit(intValue);
157+
} else {
158+
ScaffoldMessenger.of(context).showSnackBar(
159+
SnackBar(
160+
content: Text(
161+
appLocalizations.lowLimitErrorMessage,
162+
style: TextStyle(color: snackBarContentColor),
163+
),
164+
backgroundColor: snackBarBackgroundColor),
165+
);
166+
}
167+
},
168+
hint: appLocalizations.accelerometerLowLimitHint,
169+
),
143170
ConfigDropdownItem(
144171
title: appLocalizations.activeSensor,
145172
selectedValue: provider.config.activeSensor,

0 commit comments

Comments
 (0)