Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Working Gryoscope example. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: | fcc13296916510f9219f704477d28c94bd474087167b4acc362e88427cbd99d1 |
User & Date: | gwlester 2018-01-30 23:33:45 |
Context
2018-01-31
| ||
21:26 | Removed Komodo project. check-in: 14968c8081 user: gwlester tags: trunk | |
2018-01-30
| ||
23:33 | Working Gryoscope example. check-in: fcc1329691 user: gwlester tags: trunk | |
02:55 | Corrections. check-in: c34bc36854 user: gwlester tags: trunk | |
Changes
Changes to Gryo_Example.tcl.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 .. 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 ... 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 ... 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 ... 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 ... 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
2000dps,divisor 16.0 divisor 16.0 full_scale_range 0x30 gryo,x,axis 0x14 gryo,y,axis 0x16 gryo,z,axis 0x18 rate 50 freq 10 } set i2cbus 1 set dIMUaddress 0x28 set range 2000dps ................................................................................ bno055 writeRegisterBlock $handle \ gyr,range [bno055 getValue2 GRY_RANGE [string toupper $range]] \ gyr,bandwidth [bno055 getValue GRY_BANDWIDTH_32HZ] \ gyr,pwrMode [bno055 getValue GRY_POWER_MODE_NORMAL] piio usleep 10 ## ## Switch to Gryo Only mode. ## bno055 writeRegister $handle operMode [bno055 getValue OPER_MODE_GYROONLY] piio usleep 20 ## ## Set divisor so that the output of our gyro axis readings can be turned ## into scaled values. ## set GyroValues(divisor) $GyroValues($range,divisor) ................................................................................ return; } ## ## Gyro: gets a full axis reading, scaled to the full scale reading. Returns ## in degrees per second. ## proc GryoAxisGeading {axis} { global GyroValues set handle $GyroValues(handle) set intValue [bno055 readRegister $handle gyr,data,$axis] return [format {%5.0f} [expr {$intValue / $GyroValues(divisor)}]] } proc ClearHistory {} { global CurrentValue set CurrentValue(history) {} } ................................................................................ after cancel $GyroValues(afterId) } set GyroValues(afterId) [after [expr {$GyroValues(rate) * 10}] ReadGyro] ## ## Read the GYROSCOPE ## set x [GryoAxisGeading x] set y [GryoAxisGeading y] set z [GryoAxisGeading z] if {abs($x - $CurrentValue(x)) > 0 || abs($y - $CurrentValue(y)) > 0 || abs($z - $CurrentValue(z)) > 0 } { LogValues $x $y $z } set CurrentValue(x) $x set CurrentValue(y) $y set CurrentValue(z) $z } proc LogValues {x y z} { global GyroValues CurrentValue #if {[info exists GyroValues(logId)]} { # after cancel $GyroValues(logId) ................................................................................ -increment 10.0 \ -format {%3.0f} \ -wrap no \ -command [format {set ::GyroValues(rate) [expr {entier([%1$s get])}]} $w.rateEnt] $w.rateEnt set 50.0 ttk::label $w.rateLbl2 \ -text { in microseconds} #ttk::label $w.frequencyLbl1 \ # -text {Logging Rate:} #ttk::spinbox $w.frequencyEnt \ # -from 1.0 \ # -to 1000.0 \ # -increment 10.0 \ # -format {%4.0f} \ # -wrap no \ # -command [format {set ::GyroValues(freq) [expr {entier([%1$s get])}]} $w.frequencyEnt] #$w.frequencyEnt set 1.0 #ttk::label $w.frequencyLbl2 \ # -text { in seconds} ttk::frame $w.buttons ttk::button $w.buttons.start \ -text {Start} \ -width 6 \ -command StartReading ttk::button $w.buttons.stop \ -state disabled \ ................................................................................ -text {Stop} \ -width 6 \ -command StopReading ttk::button $w.buttons.reset \ -text {Clear Log} \ -width 10 \ -command {.main.history.data delete [.main.history.data children {}]} grid configure $w.busLbl $w.busCMB $w.addrLbl $w.addrEnt $w.rangeLbl $w.rangeCMB x -padx 2 -sticky ew grid configure $w.rateLbl1 $w.rateEnt $w.rateLbl2 x x x x -padx 2 -sticky ew #grid configure $w.frequencyLbl1 $w.frequencyEnt $w.frequencyLbl2 x x x -padx 2 -sticky ew grid configure $w.buttons -columnspan 7 -sticky ew -pady 3 grid configure x $w.buttons.start x $w.buttons.stop x $w.buttons.reset x -sticky ew grid columnconfigure $w.buttons {0 2 4 6} -weight 1 grid columnconfigure $w 6 -weight 1 } |
| > > | | | > > > > > > > > > > > > > > | > > > > | | | | | | > > | | > > > > > > > > > > > > | | | | | | < < > | < > > > | > |
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 .. 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 ... 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 ... 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 ... 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 ... 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
2000dps,divisor 16.0 divisor 16.0 full_scale_range 0x30 gryo,x,axis 0x14 gryo,y,axis 0x16 gryo,z,axis 0x18 rate 50 digits 5 decimals 1 minChange 0.1 } set i2cbus 1 set dIMUaddress 0x28 set range 2000dps ................................................................................ bno055 writeRegisterBlock $handle \ gyr,range [bno055 getValue2 GRY_RANGE [string toupper $range]] \ gyr,bandwidth [bno055 getValue GRY_BANDWIDTH_32HZ] \ gyr,pwrMode [bno055 getValue GRY_POWER_MODE_NORMAL] piio usleep 10 ## ## Switch to IMU mode so autocalibration happens. ## bno055 writeRegister $handle operMode [bno055 getValue OPER_MODE_IMU] piio usleep 20 ## ## Set divisor so that the output of our gyro axis readings can be turned ## into scaled values. ## set GyroValues(divisor) $GyroValues($range,divisor) ................................................................................ return; } ## ## Gyro: gets a full axis reading, scaled to the full scale reading. Returns ## in degrees per second. ## proc GryoAxisGeading {axis oldValue} { global GyroValues set handle $GyroValues(handle) set intValue [bno055 readRegister $handle gyr,data,$axis] set digits $GyroValues(digits) set decimals $GyroValues(decimals) incr digits $decimals if {$decimals} { ## ## Account for the decimal point ## incr digits } ## ## Account for the sign ## incr digits set newValue [format "%${digits}.${decimals}f" [expr {$intValue / $GyroValues(divisor)}]] if {$newValue != $oldValue && abs($newValue - $oldValue) < $GyroValues(minChange)} { set newValue $oldValue } return $newValue } proc ClearHistory {} { global CurrentValue set CurrentValue(history) {} } ................................................................................ after cancel $GyroValues(afterId) } set GyroValues(afterId) [after [expr {$GyroValues(rate) * 10}] ReadGyro] ## ## Read the GYROSCOPE ## set x [GryoAxisGeading x $CurrentValue(x)] set y [GryoAxisGeading y $CurrentValue(y)] set z [GryoAxisGeading z $CurrentValue(z)] if {$x != $CurrentValue(x) || $y != $CurrentValue(y) || $z != $CurrentValue(z) } { LogValues $x $y $z } set CurrentValue(x) $x set CurrentValue(y) $y set CurrentValue(z) $z return } proc LogValues {x y z} { global GyroValues CurrentValue #if {[info exists GyroValues(logId)]} { # after cancel $GyroValues(logId) ................................................................................ -increment 10.0 \ -format {%3.0f} \ -wrap no \ -command [format {set ::GyroValues(rate) [expr {entier([%1$s get])}]} $w.rateEnt] $w.rateEnt set 50.0 ttk::label $w.rateLbl2 \ -text { in microseconds} ttk::label $w.numDigitsLbl \ -text {Digits before decimal} ttk::combobox $w.numDigitsCMB \ -textvariable ::GyroValues(digits) \ -values [list 3 4] \ -state readonly ttk::label $w.numDecimalsLbl \ -text {Digits after decimal} ttk::combobox $w.numDecimalsCMB \ -textvariable ::GyroValues(decimals) \ -values [list 1 2 3 4] \ -state readonly ttk::label $w.minChangeLbl1 \ -text {Ignore less than} ttk::spinbox $w.minChangeEnt \ -from 0.1 \ -to 200.0 \ -increment 0.1 \ -format {%5.1f} \ -wrap no \ -textvariable ::GyroValues(minChange) ttk::label $w.minChangeLbl2 \ -text {dps change} ttk::frame $w.buttons ttk::button $w.buttons.start \ -text {Start} \ -width 6 \ -command StartReading ttk::button $w.buttons.stop \ -state disabled \ ................................................................................ -text {Stop} \ -width 6 \ -command StopReading ttk::button $w.buttons.reset \ -text {Clear Log} \ -width 10 \ -command {.main.history.data delete [.main.history.data children {}]} $w.minChangeEnt set $::GyroValues(minChange) grid configure $w.busLbl $w.busCMB $w.addrLbl $w.addrEnt $w.rangeLbl $w.rangeCMB x -padx 2 -sticky ew grid configure $w.rateLbl1 $w.rateEnt $w.rateLbl2 x x x x -padx 2 -sticky ew grid configure $w.numDigitsLbl $w.numDigitsCMB $w.numDecimalsLbl $w.numDecimalsCMB x x x -padx 2 -sticky ew grid configure $w.minChangeLbl1 $w.minChangeEnt $w.minChangeLbl2 x x x x -padx 2 -sticky ew grid configure $w.buttons -columnspan 7 -sticky ew -pady 3 grid configure x $w.buttons.start x $w.buttons.stop x $w.buttons.reset x -sticky ew grid columnconfigure $w.buttons {0 2 4 6} -weight 1 grid columnconfigure $w 6 -weight 1 } |