Skip to content

Commit

Permalink
Addressed linting warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflip committed Nov 2, 2023
1 parent 7501b70 commit def8a57
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Ev3LangScala/src/ev3dev4s/actuators/Ev3Led.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ev3dev4s.actuators

import ev3dev4s.scala2measure.Conversions._
import ev3dev4s.scala2measure.LedIntensity
import ev3dev4s.sysfs.ChannelRewriter

import java.nio.file.Path
import ev3dev4s.scala2measure.LedIntensity
import ev3dev4s.scala2measure.Conversions._

/**
*
Expand All @@ -14,7 +14,7 @@ import ev3dev4s.scala2measure.Conversions._

sealed case class Ev3Led(side: Int) extends AutoCloseable {

import ev3dev4s.actuators.Ev3Led.{Color, brightest, darkest, Off, Red, Green, Yellow}
import ev3dev4s.actuators.Ev3Led.{Color, Off, Red, Green, Yellow} // brightest, darkest

val rootName = "/sys/class"
//noinspection SpellCheckingInspection
Expand Down
1 change: 0 additions & 1 deletion Ev3LangScala/src/ev3dev4s/lego/Gyroscope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ev3dev4s.lego

import ev3dev4s.scala2measure.Degrees
import ev3dev4s.sensors.{Ev3Gyroscope, SensorPort, SensorPortScanner}
import ev3dev4s.sysfs.UnpluggedException

/**
*
Expand Down
2 changes: 1 addition & 1 deletion Ev3LangScala/src/ev3dev4s/lego/Motors.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ev3dev4s.lego

import ev3dev4s.actuators.{Motor, MotorCommand, MotorPort, MotorPortScanner, MotorState, MotorStopCommand}
import ev3dev4s.actuators.{Motor, MotorCommand, MotorPort, MotorPortScanner, MotorStopCommand}
import ev3dev4s.scala2measure.{Degrees, DegreesPerSecond, MilliSeconds}
import ev3dev4s.scala2measure.Conversions._
import ev3dev4s.os.Time
Expand Down
2 changes: 1 addition & 1 deletion Ev3LangScala/src/ev3dev4s/scala2measure/Measured.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait Measured[M <: Measured[M]] extends Any {
//noinspection
def toString(): String // todo figure out def toString(): String

def unary_-(): M = create(-this.v) // todo add type annotation when allowed
def unary_- : M = create(-this.v)

def +(m: M): M = create(this.v + m.v)

Expand Down
9 changes: 6 additions & 3 deletions Ev3LangScala/src/ev3dev4s/sensors/Ev3Gyroscope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import scala.collection.immutable.ArraySeq
* @author David Walend
* @since v0.0.0
*/
//noinspection ScalaUnnecessaryParentheses
case class Ev3Gyroscope(override val port: SensorPort, initialSensorDir: Option[Path])
extends MultiModeSensor(port, initialSensorDir.map(MultiModeSensorFS.Value0SensorFS)) { //todo change to Value01SensorFS to support GYRO-G&A

Expand Down Expand Up @@ -46,7 +47,7 @@ case class Ev3Gyroscope(override val port: SensorPort, initialSensorDir: Option[
sealed case class HeadingMode() extends Mode {
val name = "GYRO-ANG"

@volatile var offset: Degrees = 0.degrees
@volatile private var offset: Degrees = 0.degrees
zero()

/**
Expand Down Expand Up @@ -75,6 +76,7 @@ case class Ev3Gyroscope(override val port: SensorPort, initialSensorDir: Option[
/**
* Angle change rate in degrees per second
*/
//noinspection ScalaUnusedSymbol
sealed case class RateMode() extends Mode {
val name = "GYRO-RATE"

Expand Down Expand Up @@ -179,13 +181,14 @@ TILT-ANG [24] Angle (2nd axis) deg (degrees) 0 1 value0: Angle (-32768 to 32767)

while ( {
try {
//noinspection ZeroIndexToHead
reportProgress(0)()
val legoPortDir: Path = scanForPortDir()
Log.log(s"legoPortDir is $legoPortDir")
reportProgress(1)()
restartSensorSoftBoot(legoPortDir)
reportProgress(2)()
!scanForSensor(port) //keep looking if no sensor found
!scanForSensor(port) // keep looking if no sensor found
} catch {
case GadgetUnplugged(_) => true
}
Expand All @@ -197,7 +200,7 @@ TILT-ANG [24] Angle (2nd axis) deg (degrees) 0 1 value0: Angle (-32768 to 32767)

reportProgress(3)()

Log.log(s"Successfully despun")
Log.log(s"Successfully de-spun")
}
}

Expand Down
3 changes: 1 addition & 2 deletions Ev3LangScala/src/ev3dev4s/sysfs/ChannelRewriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package ev3dev4s.sysfs
import java.nio.ByteBuffer
import java.nio.channels.FileChannel
import java.nio.charset.StandardCharsets
import java.nio.file.{AccessDeniedException, Path, StandardOpenOption}
import scala.annotation.tailrec
import java.nio.file.{Path, StandardOpenOption}

/**
*
Expand Down
1 change: 1 addition & 0 deletions Ev3LangScala/src/ev3dev4s/sysfs/GadgetPortScanner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import scala.collection.immutable.ArraySeq
* @author David Walend
* @since v0.0.0
*/
//noinspection ScalaUnnecessaryParentheses
abstract class GadgetPortScanner[P <: Port](gadgetDir: File, ports: Array[P]) {

val namesToPorts: Map[Char, P] = ports.map { p => p.name -> p }.toMap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ev3dev4s.sensors.gyroscope.examples

import ev3dev4s.actuators.{Motor, MotorCommand, MotorPort, MotorStopCommand, MotorState}
import ev3dev4s.actuators.{Motor, MotorCommand, MotorPort, MotorStopCommand}
import ev3dev4s.sensors.{Ev3Gyroscope, Ev3KeyPad}
import ev3dev4s.{Ev3System, Log}
import ev3dev4s.scala2measure.Degrees
import ev3dev4s.scala2measure.{Degrees, DegreesPerSecond, DutyCycle, MilliMeters}
import ev3dev4s.scala2measure.Conversions._
import ev3dev4s.scala2measure.DegreesPerSecond
import ev3dev4s.scala2measure.DutyCycle

/**
*
Expand Down Expand Up @@ -98,15 +96,15 @@ object GyroDriveStraight extends Runnable {
val leftIdeal = ((dutyCycle + steerAdjust) / 10.unitless).dutyCyclePercent
val rightIdeal = ((dutyCycle - steerAdjust) / 10.unitless).dutyCyclePercent
(leftIdeal, rightIdeal)
//todo for fractions
//val (leftSteering, rightSteering) = (leftIdeal,rightIdeal)
//todo for fractions
//if(leftIdeal != rightIdeal) (leftIdeal,rightIdeal)
//else if(steerAdjust.v > 0) (leftIdeal+1,rightIdeal)
//else if(steerAdjust.v < 0) (leftIdeal,rightIdeal+1)
//else (leftIdeal,rightIdeal)
//todo speed up very slow movement by 10. Not sure this is usefulif(leftSteering >= 10 && rightSteering >= 10) (leftSteering,rightSteering)
//todo speed up very slow movement by 10. Not sure this is useful else (leftSteering+10,rightSteering+10)
// todo for fractions
// val (leftSteering, rightSteering) = (leftIdeal,rightIdeal)
// todo for fractions
// if(leftIdeal != rightIdeal) (leftIdeal,rightIdeal)
// else if(steerAdjust.v > 0) (leftIdeal+1,rightIdeal)
// else if(steerAdjust.v < 0) (leftIdeal,rightIdeal+1)
// else (leftIdeal,rightIdeal)
// todo speed up very slow movement by 10. Not sure this is useful: if(leftSteering >= 10 && rightSteering >= 10) (leftSteering,rightSteering)
// todo speed up very slow movement by 10. Not sure this is useful else (leftSteering+10,rightSteering+10)
}

val (leftDutyCycle, rightDutyCycle) = dutyCyclesFromAdjust()
Expand Down Expand Up @@ -209,7 +207,7 @@ object GyroDriveStraight extends Runnable {
/**
* Adjust the speed based on the current gyro heading to drive in an arc.
* This method assumes the goal absolute postions have already been written
* This method assumes the goal absolute positions have already been written
*
* @param goalHeading that the gyroscope should read during this traverse
* @param averageSpeed degrees/second for moving the robot quickly
Expand Down Expand Up @@ -270,12 +268,12 @@ object GyroDriveStraight extends Runnable {

object Robot {

val driveWheelDiameter = 11.studs
val driveWheelCircumference = (driveWheelDiameter.v * Math.PI.toFloat).mm
val driveWheelDiameter: MilliMeters = 11.studs
val driveWheelCircumference: MilliMeters = (driveWheelDiameter.v * Math.PI.toFloat).mm

val robotWheelbase = 18.studs
val robotWheelbase: MilliMeters = 18.studs

val keypad = Ev3System.keyPad
val keypad: Ev3KeyPad.type = Ev3System.keyPad

val gyroscope: Ev3Gyroscope = Ev3System.portsToSensors.values.collectFirst { case gyro: Ev3Gyroscope => gyro }.get
val headingMode: gyroscope.HeadingMode = gyroscope.headingMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import ev3dev4s.scala2measure.Conversions._
import ev3dev4s.sensors.Ev3KeyPad
import ev3dev4s.scala2measure.DutyCycle


/**
* A test of time to run a reasonable control loop for various comparisons
*
* Baseline - before messing with unit-based numbers in controls
* 1638416904531 13929 loop closures in 60000 for 4.30756 milliseconds per loop closure
*
* With my own units for Degrees and Percent (duty cyle)
* With my own units for Degrees and Percent (duty cycle)
* 1639715964387 14436 loop closures in 60000 for 4.1562757 milliseconds per loop closure
*
* With my own universal trait for the arithmetic operations
Expand Down
3 changes: 0 additions & 3 deletions Ev3LangScalaExample/src/ev3dev4s/timing/Simplest.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ev3dev4s.timing

import ev3dev4s.Ev3System
import ev3dev4s.actuators.Ev3Led

/**
* Run via
*
Expand Down

0 comments on commit def8a57

Please sign in to comment.